Interpret tags using a look-up table

Copper Contributor

I would like to use single letter tags in that cell and then have a formula that interprets those tags based on a look-up table.

For example, I might be recording genres and have a look-up table that records:

ccomedy
hhorror
ddrama

 

then when I'm making a record of an item, in a cell I write single letter tags for all genres I want and then have a formula to look these up, e.g. (first column manually entered, second column generated through a formula)

hThis contains horror.
chThis contains comedy. This contains horror.
dhThis contains horror. This contains drama.

 

Ideally, I would also like this future-proofed in the sense that if I add extra rows to the look-up table, the function does not need to be updated, but will include these rows as well.

 

Also, ideally I would like it to be able to count occurrences and output something like 

hThis contains 1 of horror.
chcThis contains 2 of comedy. This contains 1 of horror.
ddhdhThis contains 2 of horror. This contains 3 of drama.

 

Thanks for any help!

4 Replies

@Blake385 

You may write the formula as below.

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(CONCAT("This contains " &

MMULT(SEQUENCE(1,LEN(A1),1,0),--(MID(A1,SEQUENCE(LEN(A1)),1)={"c","h","d"}))&" of "&{"comedy","horror","drama"}&". "),"This contains 0 of comedy. ",""),"This contains 0 of horror. ",""),"This contains 0 of drama. ","")

Starrysky1988_0-1648966808979.png

 

 

Thank you very much! Are you able to advise how I could make the formula reference a look-up table so that the 'tags' could easily be changed in future?

@Blake385 I would have thought that you could refer to the result of  =VALUETOTEXT(SUBSTITUTE(ARRAYTOTEXT(E1:E3)," ",""))

in place of "c","h","d", but I am not able to make it work.  Maybe one of the Excel Gurus will come up with a way to use that or something like it.

Doug_Robbins_Word_MVP_0-1648975911342.png

 

@Blake385 

Here is the formula with the reference.

=CONCAT(IF(MMULT(SEQUENCE(1,LEN(A4),1,0),--(MID(A4,SEQUENCE(LEN(A4)),1)=$A$1:$C$1))=0,"",

"This contains "&MMULT(SEQUENCE(1,LEN(A4),1,0),--(MID(A4,SEQUENCE(LEN(A4)),1)=$A$1:$C$1))&" of "&$A$2:$C$2&". "))

Starrysky1988_0-1648980616527.png

If you can use LET function, you may shorten the formula as below.

=LET(A,MMULT(SEQUENCE(1,LEN(A4),1,0),--(MID(A4,SEQUENCE(LEN(A4)),1)=$A$1:$C$1)),CONCAT(IF(A=0,"",

"This contains "&A&" of "&$A$2:$C$2&". ")))