BestMordaEver
BestMordaEver

Reputation: 25

Manual data tagging and lookup

I need a system that allows to filters entries by different text tags.

Say we store info about some products. We have Red Apples, Pears, Watermelons, Cucumbers, Peppers and Bread. We store them in sheet named "Data" in column A. Next columns are occupied by tags, like Red Apples are Red, Sweet, Fruit, Unpacked; Peppers are Red, Spicy, Veggie, Packed; Bread is just Packed.

Then on another sheet we have a dedicated range, say A1:A10, which can accept any data tag, like Spicy or Packed. What I need is when somebody enters Spicy and Packed in this range, it looks up all items that are Spicy and Packed and displays them, so in this case it would display Peppers in B1 cell.

To recap: Data!A:A - entry names, Data!B:Z - tags, Main!A1:A10 - tags entered by user, Main!B:B - entries with tags, that correspond to those entered in A1:A10.

I was trying to use FILTER, but I can't figure out how to select proper condition ranges. I feel like this should be possible within this system and I really don't want to delve into scripting field.

Upvotes: 0

Views: 226

Answers (3)

player0
player0

Reputation: 1

if Data sheet looks like this:

0

and you need "constructive" list, you can do:

=SORT(FILTER(Data!A2:A, REGEXMATCH(TRANSPOSE(QUERY(TRANSPOSE(Data!B2:Z),,999^99)), 
 TEXTJOIN("|", 1, A1:A10))))

0


spreadsheet demo


0

if you need a "destructive" list do:

=ARRAYFORMULA(SORT(QUERY({Data!A2:A, TRANSPOSE(QUERY(TRANSPOSE(Data!B2:Z),,999^99))}, 
 "select Col1 where "&TEXTJOIN(" and ", 1, IF(A1:A10<>"", 
 "Col2 contains '"&A1:A10&"'", ))&"", 0)))

0

Upvotes: 0

BestMordaEver
BestMordaEver

Reputation: 25

There is a pretty simple solution to this.

You would need to add a helper column and count how many tags does your item has from the listed ones, using this formula

=SUM(ARRAYFORMULA(COUNTIF(B1:1,'Main'!$A$1:$A$10)))

1

Next, in your presentation sheet reserve some place where you can enter tags - one at a time. In my case, it's range A1:A10. Then just paste this formula anywhere else

=IFERROR(FILTER(Data!$B:$B,Data!$A:$A=(10-COUNTBLANK($A$1:$A$10))),"")

At that place, all suitable elements will show up. I also added sorting to the formula, cause why not.

2 3

You can use more tags, for that just increase the tag range and edit formula so when there are no tags entered, COUNTIF gives 0.

Upvotes: 0

a-burge
a-burge

Reputation: 1574

This can be achieved using a helper column to collect all the tags and then a =query() formula.

1) Start by creating a multi-tag column using either =join() or =textjoin(), capturing all the potential tags for each product.

Textjoin to multi-tag

2) Then use this answer to help you create the =query() formula needed.

Query for result

Upvotes: 1

Related Questions