Function Problems

Excel Formula for Quantity Discounts and Charge-Code Pricing

Aamir Naveed AkramAamir Naveed Akram Oct 26, 2026 868 views

Question details

The user needs an Excel formula to calculate product costs dynamically by matching products to specific charge codes from a reference table and multiplying them by quantities.

How to Calculate Quantity Discounts and Charge-Code Pricing in Excel
Product
Excel
Device & OS
not provided
Scenario
Setting up a dynamic pricing spreadsheet that automatically determines the final cost based on varying quantity sizes and corresponding categorized charge codes.
Observed behavior
Retrieving the correct unit price matched to different charge codes and summing up the total value accurately based on product quantities.
Before you start

Ensure your pricing reference data is formatted as an official Excel Table (using Ctrl+T) and that your charge code column headers use consistent names (e.g., 'Charge Code 1') to allow for accurate structured references.

Solution 1Recommended

Use XLOOKUP, SUMIF, and SUMPRODUCT to Calculate Costs

Combine these powerful lookup and math functions to dynamically match charge codes, retrieve specific item prices, and multiply them by quantities.

By nesting SUMIF and XLOOKUP inside a SUMPRODUCT function, Excel can pull an entire pricing column based on a matched header, sum the prices for selected products, and calculate the final quantity cost automatically.

1
Rename reference table headers

Navigate to your pricing reference table and rename the headers across your price columns sequentially, such as 'Charge Code 1' through 'Charge Code 4', ensuring they exactly match the terminology used in your lookup table.

2
Enter the combined array formula

Select the target cell for your total cost and enter the formula: =IF([@[Charge Code]]="","",SUMPRODUCT(SUMIF(Table2[Tests],Table1[@[Test1]:[Test8]],XLOOKUP(Table1[[#Headers],[Charge Code]]&" "&[@[Charge Code]],Table2[[#Headers],[Charge Code 1]:[Charge Code 4]],Table2[[Charge Code 1]:[Charge Code 4]]))*[@Quantity]))

3
Apply formula to the entire column

Press Enter to execute the formula. If your data is formatted as a structured table, the formula will automatically spill down the entire column to calculate prices for all rows.

Use XLOOKUP, SUMIF, and SUMPRODUCT to Calculate Costs
Understanding #Headers in Formulas: In structured table formulas, [#Headers] specifically refers to the column headers of the table. This allows the XLOOKUP function to search horizontally across the top row to find the matching charge code category.

Easily Manage Pricing Data and Complex Formulas with WPS Spreadsheet

WPS Spreadsheet fully supports advanced lookup and array functions like XLOOKUP, SUMIF, and SUMPRODUCT, making it easy to build dynamic pricing models, handle structured tables, and calculate quantity discounts.

  1. 1. Open your workbook: Launch WPS Spreadsheet and open your existing pricing or charge-code workbook.
  2. 2. Format data as tables: Select your data ranges and use the 'Format as Table' feature under the Home tab to enable structured references.
  3. 3. Input the formula: Click into the desired total cost cell and paste your combined XLOOKUP and SUMPRODUCT formula into the formula bar.
  4. 4. Calculate and fill: Hit Enter to calculate the total, and drag the fill handle down to apply your dynamic pricing formula to all remaining entries.
Full support for advanced Excel array formulas including XLOOKUP and SUMPRODUCT.Seamless compatibility with Microsoft Excel (.xlsx) formats and structured table references.Free, lightweight, and user-friendly interface for professional data analysis.
QA img-9

Frequently Asked Questions

What does #Headers mean in an Excel formula?

In Excel structured references, [#Headers] refers to the top header row of a formatted Table. It allows formulas to look up or match values based on the specific text of the column names rather than relying on static cell ranges like A1:D1.

Why is XLOOKUP returning an error in my charge code formula?

XLOOKUP will return an error (such as #N/A) if the lookup value doesn't exactly match the headers in your reference table. Ensure there are no trailing spaces in your cells and that the charge code names match perfectly across both tables.

Can I use VLOOKUP instead of XLOOKUP for calculating charge code prices?

While VLOOKUP can retrieve individual prices, XLOOKUP is highly recommended for this scenario because it can return an entire array or column dynamically based on a matched header, making it much easier to combine with SUMPRODUCT to multiply against quantities.