Filtering a Non-Unique Data Set in Google Sheets - google-sheets

I have a list of recipe, and I also have a list of sold menu. Is there any way that can filter the recipe (can be with query, or not) by looking at the menu (that can repeat more than once)?
https://docs.google.com/spreadsheets/d/1Ire32u7kELCAu07AHiTGt8yoXwCWDpvT77nQYSN21DU/edit#gid=0
This is the sample case
A2:B7 is the list of recipe
D2:D7 is the list of menu sold
F2:F13 is the desired result
Arrayformula is preferred since I don't have to drag down again when the data set get bigger.

try:
=FLATTEN(BYROW(D2:D7, LAMBDA(x, TRANSPOSE(FILTER(A2:A7, B2:B7=x)))))

In case you have unmatching amount of items per menu (I added two extra elements to tenderloin), you can try this other option so you don't have empty spaces:
=TRANSPOSE(SPLIT(JOIN(",",BYROW(D2:D,LAMBDA(r,IF(r="",,JOIN(",",FILTER(A2:A, B2:B=r)))))),","))

Another solution using REDUCE:
=REDUCE("recipe used",D2:D10,LAMBDA(a,c,{a;FILTER(A2:A10,B2:B10=c)}))

Related

Is it possible to give a cell a different value than it displays?

What I mean by this is maybe explained easiest with an example:
I habe a list of items and every item has a name and an ID.
I want to sort that list by ID, with the exception to have item "XYZ" with ID 24 alwas on first place. So I would like to give it's ID-cell the value 0 (for sorting) but it should still show the value 24.
Sounds weird and is probably not possible?
Edit: I want it to look like this:
If the user is sorting (using the filter drop down menu) by ID column, it should be sorted as it's in this picture.
I found a solution for the first ID (Hans): Custom number format for that cell:"0;0;"24". It will show the value 0 as '24'. That doesn't help for Franz tho. Here I want a value between 5 and 7 showed as '??'.
A possible solution would be creating a second ID and sorting the values based on this new ID. Something like this:
If you are sorting through formula in other columns you can use:
=SORT(A2:B,MAP(B2:B,LAMBDA(id,IF(id=24,0,id))),1)
Exclude that first item from sorting then merge again. Try the following formula.
={A1:B2;SORT(A3:B,2,1)}
Built an array youself for sorting with IF(A1:A7=24,0,A1:A7), so that XYZ will have its weight as 0,
place it next to your data as the 3rd column with {},
use QUERY() to sort the data and get rid of the 3rd column.
Formula:
=ArrayFormula(
QUERY({A1:B7,IF(A1:A7=24,0,A1:A7)},
"Select Col1,Col2 Order By Col3 ASC",
1)
)
I found the solution (with a little help):
For only the cells you want to show "Something else" but be handled as the values, edit the Custom number format to:
By this, it will always show what you put in there, no matter what value the cell has.

Indirect formula referencing of formula in Google sheets

I have a a Google sheet which have multiple tabs in them
I use formula to get the consolidated info from the known names of the tabs as shown below
=UNIQUE({Appliances!A2:B;'Base, Trim & Crown'!A2:B;'Bathroom Accessories'!A2:B;'Bathroom plumbing'!A2:B;Cabinetry!A2:B;Carpet!A2:B;Closets!A2:B;'Entry Door'!A2:B;'Exterior and Interior Stone'!A2:B;'Exterior Lighting and Fans'!A2:B;'Exterior Siding'!A2:B;Fireplaces!A2:B;'Garage Doors'!A2:B;Gutter!A2:B;'Interior Door'!A2:B;'Kitchen Plumbing'!A2:B;'Paint Color'!A2:B;'Patio Stone'!A2:B;Roofing!A2:B;Slab!A2:B;Staircase!A2:B;Tile!A2:B;'Timbers, Beams & Ceilings'!A2:B;'Windows & Multislides'!A2:B;'Wood Flooring'!A2:B})
Suppose if I add a new sheet tab, this formula need to be updated again, which is cumbersome for me. So I am thinking is it possible to have a range in MASTER sheet that lists all sheetnames one below the other A2:A6 and synamically generate the sheet formula using indirect referencing?
So if I just add the new tab sheet name in MASTER the formula results are auto updated.
A2:A32 contains the list of sheetnames
=INDIRECT(CONCATENATE("{",TEXTJOIN(";",true,ARRAYFORMULA("'" &A2:A32 &"'!" & "A2:B")),"}"))
Well, first of all, INDIRECT doesn't work with ArrayFormula, sadly (I wish). But secondly, what's so cumbersome about updating the formula you have? Just format it like this:
=UNIQUE({
Appliances!A2:B;
'Base, Trim & Crown'!A2:B;
'Bathroom Accessories'!A2:B;
'Bathroom plumbing'!A2:B;
Cabinetry!A2:B;
Carpet!A2:B;
Closets!A2:B;
'Entry Door'!A2:B;
'Exterior and Interior Stone'!A2:B;
'Exterior Lighting and Fans'!A2:B;
'Exterior Siding'!A2:B;Fireplaces!A2:B;
'Garage Doors'!A2:B;
Gutter!A2:B;'Interior Door'!A2:B;
'Kitchen Plumbing'!A2:B;
'Paint Color'!A2:B;
'Patio Stone'!A2:B;
Roofing!A2:B;
Slab!A2:B;
Staircase!A2:B;
Tile!A2:B;
'Timbers, Beams & Ceilings'!A2:B;
'Windows & Multislides'!A2:B;
'Wood Flooring'!A2:B
})
Just add it where you want on the above list, leaving out the semicolon on the last item. (I'm not sure if you meant double quotes or not, so I left it as is.)
Or, if you really want to generate the sheet names from a list, you can use this, based on your above formula:
=ArrayFormula(TEXTJOIN(
";"&CHAR(10),
1,
"'"&SORT(FILTER(A:A,LEN(A:A)))&"'!A2:B"
))
which sorts in alphabetical order too. This outputs something you can copy+paste into your first formula.

IF returns certain value if cell contains a certain phrase, but no blanks/N/A in between

I've tried looking for an answer to this online for a few hours now, but I just can't work out how you'd describe it, or find an appropriate answer.
I have a spreadsheet where I'm wanting to pull out an ID in Column A into a separate tab, but only if it contains a certain phrase that's contained in Column E. In this separate tab, I then don't want there to be any gaps in between the IF statements.
So for example I want the next tab to pull through the Action ID if column E contains 'Client'. If it doesn't, it searches the next row and so on until it finds one that does contain 'Client'. Row 2 on the separate tab would then continue the search, but it wouldn't be filled with something if it doesn't find the word 'Client' - it instead would continue searching down until it found one that has the word in.
So for example - if the first ID that contains the right phrase is in Row 5, I want it to appear on the separate tab in Row 2, underneath the heading. Then, if the second ID with the correct phrase in column F is in Row 11 for example on the main tab, I then want it to be pulled through to Row 3 on the separate tab. And so on..
This will then allow me to do lookups for the rest of the values I want to input on the separate tab.
I've tried as many different IF statements as I can, but it's just not having it.
Any advice would be really appreciated.
You can use INDEX and AGGREGATE combination:
=IFERROR(INDEX($A$2:$A$6,AGGREGATE(15,6,1/($E$2:$E$6="Client")*ROW($E$2:$E$6)-1,ROW()-1)),"")
In Google Sheets you can use FILTER (docs) for that. Place it in the top cell of your column.
={
"Your Header";
IFNA(FILTER(A2:A, B2:B = "Client"))
}
If A2:A and B2:B are from other tab named My Tab it will be 'My Tab'!A2:A and 'My Tab'!B2:B.

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.
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.
2)
Then use this answer to help you create the =query() formula needed.
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)))
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.
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.
if Data sheet looks like this:
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))))
spreadsheet demo
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)))

How can I filter my search in a column on google sheet which collects data from a form?

I would like to perform a multi criteria search of data in a column- contains data of check boxes(more than one option chosen).
For a clearer picture of what I am trying to do, screenshot below is a question in a form
Data from the form are saved in sheets like below,
So my concern here is if I would like to search/filter for the rows that contain "Commercial", the rows with Commercial,Engineering doesn't show up. That's definitely not an effective search.
Any advise on how can I go about this issue is kindly appreciated. If
Let's say you have your form in the response sheet in columns A to P, with the multiple choice in col D. If you want to filter your data on the word 'Commercial' you can either do:
=filter(A2:P, regexmatch(A2:P, "Commercial"))
or use query():
=query(A2:P, "select * where B contains 'Commercial' ")
Note: depending on your locale you may have to change the commas to semi-colons in order for the formulas to work.
I hope that helps ?
Following JPV's answer, I developed a line to make the query useful if you want to cross two categories. Let's suppose that someone in your checkbox example had picked all the options (IT, HR, Commercial, Engineering); and that you have created the cell with the dropdown option box in cell B1 with all your options, as JPV said.
Then, you want to filter and see all the people who had chosen IT and Commercial. You would, for that, create a second cell with the dropdown option box in, lets say C1; and then your query would be:
=query(A2:P, "select * where B contains '"&B1&"' and B contains '"&C1&"' ")
=FILTER(MOBILE!A2:E2000, ISNUMBER(SEARCH(A1,MOBILE!A2:A2000)))
SEARCH function will return a number of the position of the searched word (A1) in the searched strings in range (MOBILE!A2:A2000).
If the result of search is a number (ISNUMBER), then filter will return the TRUE rows result from the range MOBILE!A2:E2000.

Resources