Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

Nested Filters in Google Sheets

$
0
0

I'm trying to use the results from one filter() in the condition parameter of another.

It seems I can get it to work once on a sheet, but all other usages do not function the same way.

Here is a sample sheet with a few tabs.

  • The "Production Stats (Expected)" is what I'm trying to achieve.
  • The "Production Stats" is what I currently have been trying.
  • The "Item Info" tab contains the size and price of various items.
  • The "Recipes" tab contains recipes for two different items with thequantity required/produced.

For some reason in the "Production Stats" tab, cell C11 works as I expect it to but cell C15 does not. Cell C11 is a successful example of what I'm trying to do elsewhere.

Does anyone see what I'm doing wrong?

Edit: Adding the contents of the relevant tabs in my sheet so this question is still useful if my sheet gets deleted. Also added in more details of what I'm trying to do. I also don't want to make this about the data, I'm not asking for help with my specific use-case. So I switched the "data" both here and in my Google Sheet to something more generic and intuitive.

The "Item Info" sheet contains a list of all items (both inputs and outputs) along with the size and price of the part/product. Order can not be relied upon and the same items may be used in different recipes:

Product                             Size Per Unit   Price Per UnitBike                                50              200Car                                 1000            25000Wheel                               10              50Breaks                              5               25Handle Bar                          5               30Seat                                25              50Steering Wheel                      15              100

The "Recipes" sheet contains all of the recipes for products. The only "products" are Bikes and Cars. It also contains the quantity of the output produced per process (so this can be more than 1) along with the required input materials and the quantity required of those materials per process cycle.

So if a bike uses 2 wheels, and you're making 10 bikes per process, you will need 20 wheels total.

Output                  Output    Input                  Input                         Quantity                         QuantityBike                    10        Wheel                  20Bike                    10        Breaks                 20Bike                    10        Handle Bar             10Bike                    10        Seat                   10Car                     5         Wheel                  20Car                     5         Breaks                 20Car                     5         Seat                   20Car                     5         Steering Wheel         5

What I'm trying to get, is a in a third sheet, to be able to list multiple products I can create (So either Bikes or Cars) and then on the same row pull in various information about the process.

  • Total size of all the input materials for the process cycle. So the size of the Input material multiplied by the quantity needed to complete an entire process cycle. This is the step I'm having issues with and asking about. Then I'll have to SUM() the resulting values among all input materials for that process. I haven't begun to tackle this yet, so I'm not asking about this SUM()ing step.
  • The total quantity of the outputs (So 10 Bikes and 5 cars in theexamples above)
  • The total size of the outputs. So 10x100=500 for bikes and 5x1000=5000 for cars.
  • The total Price of the outputs. So 200x10=2000 for bikes and 5x25000= 125000 for cars.

So the final result I'm looking to get is:

Output  Total       Output    Total        Total         Input Size  Quantity  Output Size  Output PriceBike    475         10        500          2000Car     875         5         5000         125000

In the sheet I'm trying to get this done in "Production Stats", I have the string "Bike" in A11 and "Car" in A15.

Then in C11 I have this formuala:

=filter('Item Info'!B$2:B, 'Item Info'!A$2:A=filter(Recipes!C$2:C, Recipes!A$2:A=index(A11:A,match(A11,A11:A,0),1)))

And in C15 I have this similar formula, but change the reference from A11 to A15 because I want it to use the value for the respective row:

=filter('Item Info'!B$2:B, 'Item Info'!A$2:A=filter(Recipes!C$2:C, Recipes!A$2:A=index(A11:A,match(A15,A11:A,0),1)))

Essentially, I want the formula to use the value in A11 and A15 to go to the "Recipes" tab and look up all the required inputs for that recipe. Then, for each of those inputs, look in the "Item Info" tab to get the size of each input. Then multiple the size of one unit by the number of units needed. And finally, SUM() up all of the results and return the total size.

I seem to be having two issues with the above formula, but I'm trying to only focus this post on one.

It seems the order of the items in the "Item Info" tab has to be in a certain order. But I thought the FILTER() would look across the entire column for matches.

And when I use the two filters individually, they return exactly what I'd expect.

Inner filter (which works correctly for the A15/C15 usage):

=filter(Recipes!C$2:C, Recipes!A$2:A=index(A11:A,match(A15,A11:A,0),1))

Then if I hardcode a single value from the above into the outer FILTER(), it works as expected as well:

=filter('Item Info'!B$2:B, 'Item Info'!A$2:A="Wheel")

Normally I'd assume it can't handle an inner Filter which returned multiple rows. But It very clearly can, because it works in the A11/C11 usage.

I'm really stumped on this.


Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>