4
0
I have four tables. The first one shows amount of ingredient each menu uses.
Menu_Ingredient
menu | ingredient | amount
--------+------------+--------
Foo | A | 0.1
Foo | B | 0.2
Bar | A | 0.3
Baz | C | 0.4
Then I have the transaction table which shows date and the menu sold.
Menu_Sold
date | menu sold
--------+------------
x | Foo
x | Foo
x | Bar
x | Baz
I leave the date blank, assuming they are all the same for now. The final table that I want is showing how much ingredient was used each month. As shown in column A,B,C. To do this I created another table in column F,G,H.
A B C F G H
month | ingredient | amount month | menu | amount
-------+------------+-------- --------+------+--------
3 x | A | ? x | Foo | 2
4 x | B | ? x | Bar | 1
5 x | C | ? x | Baz | 1
Here is the formula I used to count the amount in H column.
=COUNTIF(Menu_Sold!B:B,Monthly_Ingredient_Used!G4)
Here is what I did to find amount of ingredient A.
- Get array of menus that contains ingredient in A3
=IF($B$3=Menu_Ingredient!B:B,Menu_Ingredient!A:A,"")
- Get amount sold in that month (here assumming all entries are in the same month, thus left blank)
=IFNA(INDEX(H:H,MATCH(IF($B$3=Menu_Ingredient!B:B,Menu_Ingredient!A:A,""),G:G,0)),0)
- Multiply by amount of ingredient used
=IFNA(INDEX(H:H,MATCH(IF($B$3=Menu_Ingredient!B:B,Menu_Ingredient!A:A,""),G:G,0)),0)*Menu_Ingredient!C:C
- SUM all amount
=SUM(IFNA(INDEX(H:H,MATCH(IF($B$3=Menu_Ingredient!B:B,Menu_Ingredient!A:A,""),G:G,0)),0)*Menu_Ingredient!C:C)
Here is an image of the result I got
Questions:
- The first three steps give the right result. When I expand an array down the column, I can see correct numbers. However in the last step, it doesn't sum the whole array and give the first element as a result.
- I also tried using VLOOKUP instead for step 2, but somehow it gives wrong lookup value and I don't understand why.
Here is the file if you want to try it out. https://1drv.ms/x/s!AgK3RJYPrJR8iGsfvXV0rrhtLiZa
Thanks for your reply! Since the number of menu can grow, I prefer not to have them as column so this doesn't really work for me. I created a helper table which looks exactly like
Menu Ingredient
table, but with month and I can achieve the same thing. However, I want to try to achieve without a helper table. The formula I have seems to do almost that. So I wonder if there is a limitation or if the formula is wrong. – Mind – 2019-06-07T16:49:13.720