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
  • 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.com
Top answer
1 of 1
1

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
  • 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.

🌐
Microsoft Support
support.microsoft.com › en-us › office › use-excel-as-your-calculator-a1abc057-ed11-443a-a635-68216555ad0a
Use Excel as your calculator - Microsoft Support
... All formula entries begin with an equal sign (=). For simple formulas, simply type the equal sign followed by the numeric values that you want to calculate and the math operators that you want to use — the plus sign (+) to add, the minus sign (-) to subtract, the asterisk (*) to multiply, ...
🌐
Excel Insider
excelinsider.com › home › excel for finance › how to calculate cost per unit in excel (3 effective ways)
How to Calculate Cost Per Unit in Excel (3 Effective Ways) - Excel Insider
August 22, 2025 - Add the variable cost to the fixed cost in order to calculate the total cost in Excel. The formula should be written as follows: If the fixed cost is per unit: =A1+B1 In this formula, A1 is the fixed cost, and B1 is the variable cost.
🌐
MyExcelOnline
myexcelonline.com › home › how to calculate per unit price fast in excel – step by step guide
How to Calculate Per Unit Price Fast in Excel - Step by Step Guide | MyExcelOnline
January 11, 2025 - In this article, I'll walk you through the steps to calculate per unit price in Excel, along with tips to customize and automate the process for your needs. Understanding cost per unit is critical for managing expenses and maximizing profits, whether you’re running a business or managing ...
🌐
ExcelDemy
exceldemy.com › home › excel formulas › how to calculate cost per unit in excel (with easy steps)
How to Calculate Cost per Unit in Excel (With Easy Steps) - ExcelDemy
June 24, 2024 - You can add new rows in the Fixed Cost and Variable Cost table to insert new costs without changing the formula. Right-click on the 13th row on the leftmost button. Select the Insert option. You’ll get a new row above the final sum. You can input new values and the rest of the table will be updated automatically. ... OSMAN GONI RIDWAN is a marine engineer who loves exploring Excel and VBA programming.
🌐
Contextures
contextures.com › formulas › lookup
Excel Annual Cost Calculator Shows Totals and Differences
October 2, 2022 - To see how the cost calculator formulas are set up, you can watch this short video. There are written notes below the video · To calculate the annual quantity, a formula checks the Max Units column, and uses that number, if one is entered. Otherwise, it looks up a number from the time units table. Then, that number is multiplied by the quantity. Because the scenarios are in named Excel tables, there are field names instead of cell references.
🌐
Excel Insider
excelinsider.com › home › excel for finance › how to calculate selling price from cost and margin in excel
How To Calculate Selling Price from Cost and Margin in Excel - Excel Insider
August 22, 2025 - In general, the formula for calculating selling price is Cost + Profit. Hence, the formula in Excel should be written like the following: =A1+B1 Here, A1 is the cost, and B1 is the amount of profit.
🌐
Reddit
reddit.com › r/excel › excel formula for cost calculation
r/excel on Reddit: Excel Formula for cost calculation
October 29, 2023 -

How do i create a code in excel for the below,

I'm trying to create formula to create exact cost for buying and selling. For example if i buy 3 case of orange for $10 and another 2 case for $12. Then when i sell 2 case it will return $20, then if i sell another 2 case, it will return $10+$12. Because i still have 1 case left from previous lot.

  1. There's 4 column A,B, C and D. A and B will have some data(price and qty) and C will be input. If user enter a value in C, D will return C*B.

Here are the conditions,

If C1==A1,

Return C1*B1 in D1

Else if, C1<A1 Return (C1*B1)+ (C1-A1)*B2

Else if, C1>A1 Return C1*A1 in D1 A1 = C1-A1

This is not a working code and probably missing some conditions. Here's an example,

Input: A = 5, 6, 4, 3 B = 50, 40, 45, 55

C = 4, 3, 2, 7

Output:

D= 200, 130, 80, 315

Output explanation:

D1 = C1B1 [ Now A1=1] D2 = (A1B1) + ((C2-A1)B2) [Now A1=0, A2 = 4] D3 = C3B2 [ A1=0, A2= 2] D4 = B22+ B34+ B4*1 [ Now A1=0, A2=0, A3=0, A4=2]

🌐
YouTube
youtube.com › drdavebond
Calculating cost functions using Microsoft Excel - YouTube
This video works through an example of calculating a cost function using both High Low analysis as well as a scatter plot to obtain the cost function. 0:00 H...
Published   May 19, 2016
Views   49K
Find elsewhere
🌐
YouTube
youtube.com › watch
How To Calculate Cost Per Unit in Excel - YouTube
In this video I will teach you how to calcuate cost per unit in Excel. Cost per unit refers to the amount of money it takes to produce one unit of your produ...
Published   September 14, 2023
🌐
Investopedia
investopedia.com › ask › answers › 042715 › how-do-i-calculate-production-costs-excel.asp
Calculate Production Costs in Excel: Step-by-Step Guide
September 30, 2025 - Also, fixed and variable costs may be calculated differently at different phases in a business's life cycle or accounting year. Whether the calculation is for forecasting or reporting affects the appropriate methodology as well. However, if the required definitions of production costs and the purpose of the accounting are known, several basic templates are available for Microsoft Excel that can help produce accurate accounting results. Exceltable.com, for example, offers several formulas for creating a table using Excel tools so that when you substitute data, the production cost of goods, works, and services is automatically calculated.
🌐
Someka
someka.net › home › blog › business › how to calculate cost of goods manufactured?
How to Calculate Cost of Goods Manufactured in Excel?
October 17, 2023 - Adding overhead costs to the already calculated direct material and labor costs, total manufacturing cost is reached. Total Manufacturing Cost = Direct Material Cost + Direct Labor Cost + Overhead Cost ... First part of the COGM formula is done.
🌐
YouTube
youtube.com › watch
How To Create Formulas in Excel to Calculate Costs - YouTube
Let's look at how to create formulas in excel to calculate costs. Create a simple formula can save you a lot of time in excel. We will look at a simple examp...
Published   August 21, 2019
🌐
The Bricks
thebricks.com › resources › guide-how-to-do-a-cost-analysis-in-excel
How to do a Cost Analysis in Excel
Known for its number-crunching prowess, Excel isn't just about rows and columns; it's about turning those numbers into meaningful insights. In this article, we're going to break down the steps needed to perform a cost analysis using Excel. From setting up your spreadsheet to using formulas that do the heavy lifting, you'll learn how to make sense of your data and draw useful conclusions.
🌐
The Bricks
thebricks.com › resources › guide-how-to-calculate-cost-per-unit-in-excel
How to Calculate Cost Per Unit in Excel
This is far better than typing in the numbers directly, as it allows your calculation to update automatically if any input costs change. The formula in cell G7, referencing our example cells, would be: ... C10 is your Total Fixed Costs ($5,200). G10 is your Total Variable Costs ($7,000). G5 is your Total Units Produced (2,000). Excel will calculate this and display the result: $6.10.
🌐
EDUCBA
educba.com › home › finance › finance resources › finance formula › total cost formula
What is the Total Cost Formula? Examples & Calculator
November 28, 2023 - Total Cost Formula = Total Fixed Costs + (Average Variable Cost x Total Units). It finds the total amount of money the business spends...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Top answer
1 of 3
1

Well, here is one way, but you don't state what the rate is between 21 and 30...

very basic, but you should be able to edit and expand as you want.

Do note that the limits (30 miles, 50 miles) and rates used in the formula all come from the sheet - so if the 30 mile limit changes to 25 miles - all you need to do is change cell A7...

2 of 3
0

I apologize for not answering sooner, but I find this question a bit difficult to address due to the complexity of formulas we can encounter. I know the one you documented is not the most complex one we might encounter, but I was not sure if that was your actual problem or if it was intended as a simple example. I have seen a variety of other things which have often thrown me for a loop.

For example, take this set of rules:

Minimum Fee is $23.50 up to $500
$501 - $2,000 = $3.05 per 100 unit increment
$2,001 - $25,000 = $14.00 per 1000 unit increment over $2,000
$25,001 - $50,000 = $10.10 per 1000 unit increment over $25,000
$50,001 - $100,000 = $7.00 per 1000 unit increment over $50,000
$100,001 - $500,000 = $5.60 per 1000 unit increment over $100,000
$500,001 - $1,000,000 = $4.75 per 1000 unit increment over $500,000
$1,000,001 - $9,999,000 = $3.65 per 1000 unit increment over $1,000,000
$10,000,001 and up = $3.65 per 1000 unit increment over $10,000,000

It does not look too different from yours except that there is an increment of something other than a single unit. In other words for the $501 to $2,000 range, $501 to $600 would all get the same additional $3.05 incremental charge. Another dollar would actually double this because it jumps to the next increment. Like your example, each range builds on the prior range. Assuming that these amounts are in colums A through F:

i   Low                 High    Fee     Base Fee    Per
0             1          500              23.50 
1           501        2,000    $3.05                100
2         2,001       25,000   $23.50               1000
3        25,001       50,000   $10.10               1000
4        50,001      100,000    $7.00               1000
5       100,001      500,000    $5.60               1000
6       500,001    1,000,000    $4.75               1000
7     1,000,001    9,999,999    $3.65               1000
8    10,000,000                 $3.65               1000

Note also that the rate declines as the amounts increase whereas yours appears to increase.

What I did with this is create a maximum value in Column H as follows:

i   Max
0   =E3
1   =INT((C4-C3)/F4)*D4
2   =INT((C5-C4)/F5)*D5
3   =INT((C6-C5)/F6)*D6
4   =INT((C7-C6)/F7)*D7
5   =INT((C8-C7)/F8)*D8
6   =INT((C9-C8)/F9)*D9
7   =INT((C10-C9)/F10)*D10
8   

The first one, where i is zero, is simply the base fee. The others are computed and copied. There is no maximum for the last row. I did not really think I needed this column but it made it easier to devise the formulas.

Assuming that I put an amount to evaluate in Cell I2, it will be evaluated as follows where the formula in row 3 (where i=0) is the set fee but all others are basically a copied formula:

i   4,950
0   =IF(I$2>=$B3,$H3,0)
1   =IF(I$2>=$B4,IF($H4="",INT((I$2-$C3)/$F4)*$D4,MIN($H4,INT((I$2-$C3)/$F4)*$D4)),0)
2   =IF(I$2>=$B5,IF($H5="",INT((I$2-$C4)/$F5)*$D5,MIN($H5,INT((I$2-$C4)/$F5)*$D5)),0)
3   =IF(I$2>=$B6,IF($H6="",INT((I$2-$C5)/$F6)*$D6,MIN($H6,INT((I$2-$C5)/$F6)*$D6)),0)
4   =IF(I$2>=$B7,IF($H7="",INT((I$2-$C6)/$F7)*$D7,MIN($H7,INT((I$2-$C6)/$F7)*$D7)),0)
5   =IF(I$2>=$B8,IF($H8="",INT((I$2-$C7)/$F8)*$D8,MIN($H8,INT((I$2-$C7)/$F8)*$D8)),0)
6   =IF(I$2>=$B9,IF($H9="",INT((I$2-$C8)/$F9)*$D9,MIN($H9,INT((I$2-$C8)/$F9)*$D9)),0)
7   =IF(I$2>=$B10,IF($H10="",INT((I$2-$C9)/$F10)*$D10,MIN($H10,INT((I$2-$C9)/$F10)*$D10)),0)
8   =IF(I$2>=$B11,IF($H11="",INT((I$2-$C10)/$F11)*$D11,MIN($H11,INT((I$2-$C10)/$F11)*$D11)),0)

The Fee for this is the sum of all of the rows (labeled i, 0 through 8 above). in this example, it would be 23.50 plus 45.75 plus 28.00 for a total of 97.25.

Not too bad. How about a set like this:

No fee if $1,000 or less
$1,001 - $5,000 = $80.00 + 3% of excess over $1,000.00 per 100 unit increment
$5,001 - $10,000 = $250.00 + 2% of excess over $5,000.00 per 500 unit increment
$10,001 - $25,000 = $350.00 + 1% of excess over $10,000.00 per 1000 unit increment
$25,001 and Over = $520.00 + 3/4% of excess over $25,000.00 per 1000 unit increment

In your formula, the initial flat amount never changes and once you've computed the amount for that range, other ranges build upon it. Here, there are steps. For example at $1,000 the fee is zero, but at $1,001, it jumps to $80 as if there were an $80 fee for the first 1000. Without boring you with the entire table, Here is the formula for computing the range from 5,001 to 10,000 assuming that G2 contains the amount to use and Row 5 colums A through E are the following:

Low     High        Rate      Minimum   Increment
 5,001   10,000     2.00%        250         500 

=($D5+$C5*INT(($G$2-($A5-1))/$E5)*$E5)*($G$2>=$A5)*OR($B5="",$G$2<=$B5)

The formula simply looks at the current row and does the computation if the amount in G2 falls within the range from Column A to Column B.

A simplification of all of the above comes when each range cumulatively builds on the prior ranges AND the rate of payment is always increasing, like the U.S. Tax Tables:

    Over    Not Over        
      0       9,525     10% of taxable income
  9,525      38,700     $952.50 plus 12% of the excess over $9,525
 38,700      82,500     $4,453.50 plus 22% of the excess over $38,700
 82,500     157,500     $14,089.50 plus 24% of the excess over $82,500
157,500     200,000     $32,089.50 plus 32% of the excess over $157,500
200,000     500,000     $45,689.50 plus 35% of the excess over $200,000
500,000                 $150,689.50 plus 37% of the excess over $500,000

Here, we can use something referred to as the "deskpad method" to shortcut the computation

Assuming that the amount to be evaluated is in G1 and these are in column A through C starting in Row 1:

Over    Not Over    Rate
      0   9,525     10.0%
  9,525  38,700     12.0%
 38,700  82,500     22.0%
 82,500 157,500     24.0%
157,500 200,000     32.0%
200,000 500,000     35.0%
500,000             37.0%

We compute the amount based on G1 as follows:

=ROUND(SUMPRODUCT($C$2:$C$8-$C$1:$C$7,$G$1-$A$2:$A$8,N($G$1>$A$2:$A$8)),0)

Note: this is not entered as an array formula.

How does this relate to your question. If the need is as simple as you stated (in other words, the rate is always increasing and we do not have any "steps" in the reimbursement, we can compute it similarly to the U.S. Tax computation.

I created these values in columns A through D starting in row 1:

Over    Not Over        
  0      20     £-      Flat Amount of £10.00
 20      50     £0.50   £10.00 plus £.50 per mile over 20 miles
 50     100     £1.00   £25.00 plus £1.00 per mile over 50 miles
100             £1.50   £75.00 plus £1.50 per mile over 100 miles

where column D is just descriptive. I put the £10.00 flat fee in Cell E1.

Assuming that G1 contains the number of miles, we would compute the reimbursement as:

=$E$1+ROUND(SUMPRODUCT($C$2:$C$5-$C$1:$C$4,$G$1-$A$2:$A$5,N($G$1>$A$2:$A$5)),2))

For example, when G1 is 52 miles, the computation is £27.00

Note: this is not entered as an array formula.

So, if this is the situation, what you would need is a place to house Columns A through C, a place to house the flat amount and a formula similar to what I provided to compute the reimbursement based on the cell housing the number of miles.

Please note that all the earlier items indicate that this formula will not be so simple if the rate is stepped or the rate declines or if the incremental unit is something other than 1 mile.

I hope that some of this makes sense. Good luck.

🌐
Quora
quora.com › How-can-I-calculate-the-total-cost-of-quantity-with-price-breaks-in-Excel
How to calculate the total cost of quantity with price breaks in Excel - Quora
Answer (1 of 5): Put the Quantity and price breaks in columns A & B as follows: Qty Price 1 20 11 18 20 16 50 13 101 12 To get the unit price for the requested quantity use the formula =VLOOKUP(D3,$A$1:$B$6,2,TRUE) where D3 is the cell to the ...
🌐
Exceltable
exceltable.com › en › master-class › calculation-production-costs
Calculation of production costs in Excel
The calculation of the planned production cost price begins with the determination of the production cost of raw materials and materials used for the production of goods (which are directly involved in the technological process). The expenses of raw materials is included in the expenses of the standards approved by the enterprise minus technological losses. These data can be taken in the technological or production department. We will reflect the norms of raw material consumption in the Excel table: Here we managed to automate only one column which is the column with the expense taking into account the technological losses.