Calculate Total Cost with Excel VLOOKUP Function

In today’s article we will show you how to calculate the total cost for a given weight using the Excel VLOOKUP function. This function will help us to find the appropriate unit price for that weight and then we can use the simple multiplication “unit price * weight” to get the total cost.

Suppose we want to purchase a batch of something, unit prices are different depending on the weight bands, usually the unit price becomes cheaper as the weight increases.

If the correspondence between weight band and unit price is provided in a table in excel worksheet, how can we find the matching unit price and calculate the total price if we know the weight? Can we just create a simple formula to get the total cost?

Look at the example below. To calculate the total cost of something with a weight of 120kg.

Calculate Total Cost with Excel VLOOKUP Function1

FORMULA

In this example, the formula is:

=VLOOKUP(D2,A2:B8,2)*D2

VLOOKUP INTRODUCTION

VLOOKUP function is a vertical lookup function in Excel, it runs a column-by-column lookup that eventually returns the value corresponding to the looked-up value in the specified column.

Syntax:

=VLOOKUP(lookup_value,table_array,col_index_num,[range_lookup])

Arguments:

  • lookup_value is the value that needs to be looked up. Make sure it is in the first column of the table. lookup_value can be a numeric value, a reference, or a text string.
  • table_array is the table in which the data needs to be looked up. Use a range reference to or a table name to represents the table.
  • col_index_num is the column number of the data to be looked up in the table_array.
  • range_lookup provides two modes for VLOOKUP; If range_lookup is TRUE or 1, the VLOOKUP function will look for an approximate match; if range_lookup is FALSE or 0, VLOOKUP returns an exact match; and it returns an error value #N/A if not found. If this argument is omitted, the default value is 1, which means that VLOOKUP returns an approximate match.

EXPLANATION

As we mentioned above, the total cost is equal to the unit price * weight. In this example, the unit price is not a fixed value, it is determined by the weight, and since the weight is given by D2, we need to know the unit price of D2, and we use Excel VLOOKUP function to retrieve the corresponding unit price.

So, in this formula:

VLOOKUP(D2,A2:B8,2) – unit price

D2 – weight of the input

In VLOOKUP(D2,A2:B8,2)

  • Lookup_value – D2 (120kg)
  • Table_array – A2:B8
  • col_index_num – 2 (returns the unit price as unit price in the second column)
  • range_lookup – 1- Approximate match (If this argument is omitted, the default value is 1)

Step#1 VLOOKUP finds the row of entered weight “120”

In this example, “120” is not listed in the first column of the table. Since the value of range_lookup is 1, VLOOKUP returns an approximate match. In approximate match mode, Excel VLOOKUP function will search for “120” in the first column until it encounters the first value greater than it, and then return to the previous row.

In this example, in “Weight” column, Excel VLOOKUP function compares each weight against with the lookup value “120”, and when coming to cell A6, it encounters the first value greater than “120” which is 150, so it returns to A5.

     

(you can compare the two pictures for better understanding the approximate match)

Step#2 VLOOKUP returns unit price in the row of weight “120”

In the previous step, we know that the row index of weight “120” is 5. Since the column index is 2, Excel VLOOKUP returns the intersection in row 5 and column 2 of table A2:B8. The intersection is B2, value in B2 is 1.23. So VLOOKUP function returns 1.23 finally.

Step#3 Calculate the formula =VLOOKUP(D2,A2:B8,2)*D2

Calculate Total Cost with Excel VLOOKUP Function1

The formula is equivalent to

=VLOOKUP(120,{0,1.78;20,1.56;50,1.41;100,1.23;150,0.91;200,0.86;250,0.74},2)*120

Calculate Total Cost with Excel VLOOKUP Function1

In step#2, we know VLOOKUP returns 1.23, so the total cost in this example is 1.23*120=147.6.

Calculate Total Cost with Excel VLOOKUP Function1

Related Functions


  • Excel VLOOKUP function
    The Excel VLOOKUP function lookup a value in the first column of the table and return the value in the same row based on index_num position.The syntax of the VLOOKUP function is as below:= VLOOKUP (lookup_value, table_array, column_index_num,[range_lookup])….

Related Posts

Build Hyperlink With VLOOKUP in Excel

You might have come across a task in which you were assigned to build hyperlinks, which seems very easy, and if you are new to excel or don't have enough experience with it, then you might wonder about doing this ...

Basic Price Discount Calculation with Excel VLOOKUP Function

We often encounter product discounts in our shopping. Depending on the level of spending, the mall will offer different percentages of discounts. Usually, the more you spend, the bigger the discount, while the less you spend, the smaller the discount. ...

Calculate Grades With VLookup in Excel

Why Should You Calculate Grades With VLookup Excel? If you're looking for a simple way to find out a student's grades, VLOOKUP Excel can do the trick. This function uses a lookup table to find the values and sort them ...

Convert State Names To Abbreviations
abbr state names1

Assume that you got a task to convert the full state's name into the abbreviations in MS Excel, and for doing this task, you might choose to do it manually, which is an acceptable way only if you don't have ...

Find and Replace Multiple Values
find replace multiple values5

This post will guide you how to find and replace multiple values at once with VBA macro or using formula  in Excel. How do I make multiple find and replace in Excel. Suppose that you have a few cells containing ...

Excel XLOOKUP Function

Excel XLOOKUP Function was added into Excel as a beta feature in August 2019 and is now accessible exclusively in Microsoft 365. (as of July 2021). However, if you fall into this category and often deal with big sets of ...

VLOOKUP Formula | Faster Trick with 2 VLOOKUPS

This post will guide you how to use 2 VLOOKUPS function to looking up data entries from a given range of cells in Microsoft Excel. VLOOKUP with 2 lookups can be faster than a single VLOOKUP in certain scenarios. The ...

VBA Macro For VLOOKUP From Another Sheet
vba macro for vlookup from another sheet1

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

VLOOKUP From Another Sheet Not Working
vlookup from another sheet not working3

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you reasons why your VLOOKUP formula is not working ...

Fix #N/A Error For VLOOKUP From Another Sheet
vlookup from anther sheet not working1

This post will show you how to fix the #N/A error why it occurs when you extract values from another sheet using VLOOKUP function in Excel 2016,2013,2010 or other Excel versions. How can you correct a #N/A error in VLOOKUP ...

Sidebar