In this blog, I’ll describe how to calculate a cumulative sum by Product ID in Power BI.Here are step-by-step instructions for calculating a cumulative sum in Power BI using a measure.
Point-1. Import the Sales table from the Data Source
Point-2. Create a Measure-
In the “Fields” pane, right-click on your table (e.g., “Sales”) and select “New Measure.”
Enter the DAX Formula:
Give your new measure a name (e.g., “Product Cumulative Sales”).
Use the following DAX formula to calculate the cumulative sum:
Product Cumulative Sales =
Var A= [Sales_] – Sum of sales
return
SUMX(
FILTER(
SUMMARIZE(ALL(Sales), Sales[Product ID],
“revenue”, [Sales_]),
[revenue]<=A),
[revenue]
)
After entering the formula, press Enter to create the measure.
Point-3 Use in Visuals:
Now you can use the “Product Cumulative Sales” measure in your visuals, such as tables, to see the cumulative sum of sales for each Product ID.
Below is the screenshot