(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to calculate cumulative sales by price range in DAX

João Barros 01 de December de 2026 2 min read

This tutorial shows how to calculate cumulative sales by price range in DAX, useful to identify revenue breakpoints by price segments. Learn how to create dynamic ranges, sum sales by range and calculate cumulative percentages — all in the context of Power BI/tabular models.

Prerequisites

  • Power BI Desktop or SSAS Tabular with a model that contains fact tables (e.g.: Sales) and product tables (e.g.: Products).
  • Price column in the Products table and SalesAmount column in the Sales table.
  • Relationship between Sales[ProductID] and Products[ProductID].

Why: without these columns and relationship you cannot attribute sales to products or group by price range. In real models it’s common to have thousands of products and millions of rows in fact tables — having a correct relationship and optimized indexes ensures fast measures. Practical example: if you have 5,000 products and annual sales of €1,000,000, you must ensure aggregations are performed over the Products dimension to obtain reliable ranges.

Step 1: Create a price range column in Products

Why: having a calculated column with ranges (bins) simplifies analysis and filters. We will create fixed ranges (e.g.: 0-50, 50-100, 100-200, >200).

PriceRange =
SWITCH(
    TRUE(),
    Products[Price] <= 50, "0-50",
    Products[Price] <= 100, "50-100",
    Products[Price] <= 200, "100-200",
    "200+"
)

Practical note: adjust the limits according to your catalog. If you have many products below €10, it may make sense to create a 0-10 range. This column is useful in tables, slicers and to ensure coherent aggregations when you mix dimensions (e.g.: Category x Price Range). In terms of performance, a calculated column in Power BI is evaluated during model processing; for large models consider creating this column at source or via Power Query.

Step 2: Sales measure per product

Why: a clean base measure enables reuse. We create a simple measure that sums SalesAmount.

Total Sales = SUM(Sales[SalesAmount])

Example: if the fact table records sales per transaction, [Total Sales] aggregates that value automatically in the report context. This measure will be the base for all subsequent measures (by range, cumulative, percentages).

Step 3: Sales by price range measure

Why: when you place PriceRange in the visual, the context already filters products; this measure ensures correct aggregation even in more complex contexts.

Sales by Price Range =
CALCULATE(
    [Total Sales],
    ALLSELECTED(Products),
    VALUES(Products[PriceRange])
)

Why use ALLSELECTED: it preserves filters applied by the user (slicers) while ignoring internal filters that could break aggregation by range. For example, if a user filters by Category = "Electronics", ALLSELECTED will allow [Sales by Price Range] to show the ranges calculated within that subset. In test scenarios with 4 ranges and total sales of €1,000,000, you might see a distribution like: 0-50 = €120,000, 50-100 = €280,000, 100-200 = €300,000, 200+ = €300,000. These numbers illustrate the distribution and help validate measures.

Step 4: Accumulated sales by price range (ordered by lower bound)

Why: cumulative by range lets you see the cumulative contribution of lower ranges to total sales. We need a consistent ordering of ranges; create an auxiliary column with the lower bound to sort.

PriceRangeOrder =
SWITCH(
    Products[PriceRange],
    "0-50", 1,
    "50-100", 2,
    "100-200", 3,
    4
)

Then create the cumulative measure using SUMX and FILTER over the ordered ranges.

Accumulated Sales by Range =
VAR CurrentOrder = MAX(Products[PriceRangeOrder])
RETURN
CALCULATE(
    SUMX(
        VALUES(Products[PriceRange]),
        [Sales by Price Range]
    ),
    FILTER(
        ALL(Products[PriceRange], Products[PriceRangeOrder]),
        Products[PriceRangeOrder] <= CurrentOrder
    )
)

Practical explanation: if the current order is 2 (range 50-100), the measure sums sales for ranges with order 1 and 2. Using the example values above, the cumulative up to 50-100 would be €120,000 + €280,000 = €400,000, or 40% of the €1,000,000 total. This technique is robust when you have other dimensions in the report, because the ALL in the FILTER body ensures the set of ranges is not limited by external contexts.

Step 5: Cumulative percentage and percentage of total

Why: viewing percentages helps prioritize ranges. First we calculate the overall total sales, then the cumulative percentage.

Total Sales All = CALCULATE([Total Sales], ALL(Products))

Accumulated Sales % =
DIVIDE([Accumulated Sales by Range], [Total Sales All])

Use DIVIDE to avoid division by zero. Format as percentage in Power BI. With the example numbers, cumulative percentages would be: 0-50 → 12%, 50-100 → 40% cumulative, 100-200 → 70% cumulative, 200+ → 100% cumulative. These percentages help answer questions like: "Which ranges generate 80% of sales?" — in the example, up to 100-200 we reach 70%, so the last range is still needed to hit 80%.

Step 6: Visualization and sorting in the report

Why: to interpret the results, create a table or bar chart visual. Put Products[PriceRange] on the axis/rows and the measures: Sales by Price Range, Accumulated Sales by Range and Accumulated Sales %.

  1. Add a table: PriceRange, Sales by Price Range, Accumulated Sales by Range, Accumulated Sales %.
  2. Sort by PriceRangeOrder (select column and choose Sort by Column > PriceRangeOrder).
  3. Add a stacked bar chart or line for Accumulated Sales % to visualize the cumulative trend.

Visually, a combined chart (bars for values by range and line for cumulative %) makes reading easier: the bars show magnitude by range and the line indicates the cumulative progression.

Verify the result

Quick checks: (1) the sum of Sales by Price Range across all ranges should equal Total Sales All; (2) Accumulated Sales by Range for the last range should equal Total Sales All; (3) Accumulated Sales % for the last range should be 100% (or approximate, if filters are applied). In a test environment, also validate with date filters (e.g.: last quarter) to ensure the measures respect slicers and temporal context. If there are discrepancies, check active filters and whether ALL/ALLSELECTED are being used correctly.

Conclusion

Now you can group products by price ranges, calculate sales by range, cumulative values and percentages in DAX — useful for segmentation and pricing. Next steps: create dynamic ranges with parameters or use automatic histogram; you have room to experiment with different limits. Tip: test with data samples (for example 1,000 rows) before applying to the full dataset, and use Performance Analyzer in Power BI to measure the impact of the measures. Tests with date filters help identify seasonal changes in contributions by range.