How can I calculate a cumulative sum in Power BI?

To calculate a cumulative sum in Power BI, you can use the DAX (Data Analysis Expressions) function called “CumulativeTotal”. This function takes the sum of a specified column and adds it to the previous rows in the same column, creating a running total. You can use this function in a measure or calculated column to display the cumulative sum in a visual or table. The syntax for this function is “CumulativeTotal()” where refers to the column you want to calculate the cumulative sum for. This allows you to easily track the total of a certain measure over time or across categories in your data.


You can use the following syntax in DAX to calculate the cumulative sum of values in a particular column in Power BI:

Cumulative Sum = 
CALCULATE (
    SUM ( 'my_data'[Sales] ),
    ALL ( 'my_data' ),
    'my_data'[Date] <= EARLIER ( 'my_data'[Date] )
)

This particular example creates a new column named Cumulative Sum that contains the cumulative sum of the values in the Sales column of the table named my_data.

The following example shows how to use this syntax in practice.

Example: How to Calculate a Cumulative Sum in Power BI

Suppose we have the following table in Power BI named my_data that contains information about sales made on various dates by some company:

Suppose we would like to add a new column that contains the cumulative sum of the values in the Sales column.

To do so, click the Table tools tab along the top ribbon, then click the New column icon:

Then type the following formula into the formula bar:

Cumulative Sum = 
CALCULATE (
    SUM ( 'my_data'[Sales] ),
    ALL ( 'my_data' ),
    'my_data'[Date] <= EARLIER ( 'my_data'[Date] )
)

This will create a new column named Cumulative Sum that contains the cumulative sum of the values in the Sales column:

Power BI cumulative sum

For example, we can see:

  • Cumulative sum of sales for first row: 6
  • Cumulative sum of sales for second row: 6 + 9 = 15
  • Cumulative sum of sales for third row: 6 + 9 + 13 = 28
  • Cumulative sum of sales for fourth row: 6 + 9 + 13 + 12 = 40

And so on.

Additional Resources

The following tutorials explain how to perform other common tasks in Power BI:

x