I don't think there is a single formula that will do what you want but a pair of macro functions can do the job easily.
The first macro function (e.g., Quantity_Cost) is a subroutine that accepts a food name as a string and a quantity as an integer. It looks up the item price in for that name in Menu Costs, multiplies that value by the quantity, and returns the product to the calling macro.
The second macro function (e.g., Total_Cost) is the main routine. It extracts the text in the corresponding cell in the Food Option column. It determines if this text represents a single Food (as in rows 1, 2, and 3 of your sample) or it represents several Foods, each enclosed in quotes, and the entire list enclosed in brackets (as in row 5)
- For a single Food, call Quantity_Cost passing the text and the quantity (not shown in your sample). Return the value from this call to the cell from which Total_Cost was called (the Cost column in your sample).
- For multiple foods, you need a loop.
- Find the first quote and note its location. If none, exit the loop.
- Find the next quote and note its location. If none, the data is malformed.
- Extract the text between, but not including, the quotes.
- Call Quantity_Cost passing the extracted text and the quantity.
- Add the value returned from this call to an accumulator.
- Repeat the loop
- Add the value returned from this call to an accumulator.
- Call Quantity_Cost passing the extracted text and the quantity.
- Extract the text between, but not including, the quotes.
- Find the next quote and note its location. If none, the data is malformed.
- Find the first quote and note its location. If none, exit the loop.
- Return the value in the accumulator to the cell from which Total_Cost was called.
You can add additional error checking as you wish. For example: check for both brackets; check for a comma between quoted foods; verify the Food exists in Menu Costs; etc.
Answer from Barry Schwarz on learn.microsoft.comVideos
=SUMPRODUCT(VLOOKUP(T(IF({1},$B$2:$B$6)),$F$2:$G$9,2,)*$C$2:$C$6*($A$2:$A$6=J2))
Somebody gives the above solution, it's great.
The answer seems to tell that(I just presume, not sure):
IF({1},$B$2:$B$6)convert cells to static array.the first argument
lookup_valueinVLOOKUPcan be array.
If you add a helper column in column D to get the price total for each row you can do it with sumif:
Put this in D2 and drag down:
=INDEX(G:G,MATCH(B2,F:F,0),1)*C2
Then this in K2:
=SUMIF(A:A,J2,D:D)
You can drag this down as well if you want to add another name to total in the next line.
Wanted to create an automated dashboard where the total price is calculated for every item as and when it is entered. Can someone help with the formula?
Hi Ben
I'm AnnaThomas and I'd be happy to help you with your question. In this Forum, we are Microsoft consumers just like yourself.
You can use the IF function in cell 3 to determine the price based on the selection in cell 1. For example:
=IF(A1=1,VLOOKUP(B1,Normal_Price_Range,2,FALSE),VLOOKUP(B1,Bundle_Price_Range,2,FALSE))
Where: A1 is the cell containing the drop-down menu selection (1 for normal price and 2 for bundle price) B1 is the cell containing the tariff selected from the drop-down menu in cell 2 Normal_Price_Range and Bundle_Price_Range are the named ranges for the normal and bundle prices respectively 2 is the column number in the named ranges that contains the prices FALSE means that the VLOOKUP function should perform an exact match
This formula will return the price from the Normal_Price_Range if the selection in cell 1 is 1, and from the Bundle_Price_Range if the selection is 2.
I hope this helps ;-), let me know if this is contrary to what you need, I would still be helpful to answer more of your questions.
Best Regards,
AnnaThomas
Give back to the community. Help the next person with this problem by indicating whether this answer solved your problem. Click Yes or No at the bottom.
Hi Anna,
Thankyou for your reply.
I have tried the example you mentioned but cannot get this to work.
I am not sure I explained how I have the sheet setup the best.
The way I need the formula to read for cell I4 will be, =IF G4= \Broadband then I4 = price range for the Broadband prices, column 2 for the price, or if G4 = \Bundle, I4 = Price range for Bundle prices, column 3 for price)
The current formula I have is =VLOOKUP(H4,'Price Sheet'!D4:E7,2,FALSE) but this only works for the Broadband prices as the Broadband is the category selected in the drown menu in cell G4.
We sell a product that has a unit price that decreases as the volume purchased increases and want to add an "unlimited" price that's based on a specific volume.
Currently, the volume increments are 0-40k, 40k-70k, 70k-100k, 100k-1M, and above 1M in column A and each increment has a unit price in column B.
I want to change that last increment to 1M-6M and add a row for 6M+ but use the specific word "unlimited" in column A.
Today, the formula to calculate the cost is: =IF(B14>A6, A3*B3+(A4-A3)*B4+(A5-A4)*B5+(A6-A5)*B6+(B14-A7)*B7, IF(B14>A5, A3*B3+(A4-A3)*B4+(A5-A4)*B5+(B14-A5)*B6, IF(B14>A4, A3*B3+(A4-A3)*B4+(B14-A4)*B5, IF(B14>A3, A3*B3+(B14-A3)*B4, B14*B3))))/B14/5000
First of all, shouldn't we be using a VLOOKUP instead of that ridiculously long formula?
... and, is there a way to create a formula that looks for the word "unlimited" instead of a number to calculate a price?