How to Calculate a Cumulative Sum in Power BI


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:

A Simple Formula for “If Contains” in Power BI
How to Write an IF Statement in Power BI
How to Write an IF Statement with Multiple Conditions in Power BI

Leave a Reply

Your email address will not be published. Required fields are marked *