0
0
Power-biHow-ToBeginner ยท 3 min read

How to Calculate Running Total in Power BI Using DAX

To calculate a running total in Power BI, use the CALCULATE function combined with FILTER and ALLSELECTED to sum values up to the current row. A common formula is: Running Total = CALCULATE(SUM(Table[Value]), FILTER(ALLSELECTED(Table), Table[Date] <= MAX(Table[Date]))).
๐Ÿ“

Syntax

The running total measure uses these DAX functions:

  • CALCULATE(): Changes the context to perform calculations.
  • SUM(): Adds up the values in a column.
  • FILTER(): Filters rows based on a condition.
  • ALLSELECTED(): Removes filters except those applied by user selections.
  • MAX(): Finds the maximum date in the current context.

This combination sums all values where the date is less than or equal to the current date, creating a running total.

DAX
Running Total = CALCULATE(
    SUM(Table[Value]),
    FILTER(
        ALLSELECTED(Table),
        Table[Date] <= MAX(Table[Date])
    )
)
๐Ÿ’ป

Example

This example shows how to create a running total measure for sales over time. Assume a table named Sales with columns Date and Amount. The measure sums all sales up to each date.

DAX
Running Total Sales = CALCULATE(
    SUM(Sales[Amount]),
    FILTER(
        ALLSELECTED(Sales),
        Sales[Date] <= MAX(Sales[Date])
    )
)
Output
Date | Running Total Sales 2024-01-01 | 100 2024-01-02 | 250 2024-01-03 | 400 2024-01-04 | 550
โš ๏ธ

Common Pitfalls

Common mistakes when calculating running totals include:

  • Using ALL() instead of ALLSELECTED(), which ignores slicers and filters and can give wrong totals.
  • Not using FILTER() properly, causing the total to sum all rows instead of up to the current date.
  • Using MAX() on the wrong column or without a proper date context.

Always ensure your date column is continuous and sorted correctly in your visuals.

DAX
/* Wrong way: ignores slicers and filters */
Running Total Wrong = CALCULATE(
    SUM(Sales[Amount]),
    FILTER(
        ALL(Sales),
        Sales[Date] <= MAX(Sales[Date])
    )
)

/* Right way: respects slicers and filters */
Running Total Correct = CALCULATE(
    SUM(Sales[Amount]),
    FILTER(
        ALLSELECTED(Sales),
        Sales[Date] <= MAX(Sales[Date])
    )
)
๐Ÿ“Š

Quick Reference

Tips for running totals in Power BI:

  • Use ALLSELECTED() to respect user filters.
  • Ensure your date column is continuous and properly formatted.
  • Use FILTER() to limit rows up to the current date.
  • Test your measure in a table visual with dates to verify results.
โœ…

Key Takeaways

Use CALCULATE with FILTER and ALLSELECTED to create running totals that respect filters.
The FILTER condition should compare dates up to the current row using MAX(Date).
Avoid ALL() if you want your running total to respond to slicers and filters.
Test running total measures in date-sorted visuals to confirm accuracy.