Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Praj8050
Helper I
Helper I

Running Total Calculation Across Multiple Categories

I am currently calculating the running total of units for Category_A using the following formula, but the result is not as expected. When I remove the date filters, the calculation works correctly. However, I need the formula to return accurate results for different date range selections.

Additionally, I would like to include Category_B in the running total calculation, with Category_A in rows, Category_B in columns, and Units in the values section.

Here is the formula I’ve used (created using Quick Measures):

Units running total =
CALCULATE(
SUM(df[Units]),
FILTER(
CALCULATETABLE(
SUMMARIZE(
df,
df[Sort (Category_A)],
df[Category_A]
),
ALLSELECTED(df)
),
ISONORAFTER(
df[Sort (Category_A)], MAX(df[Sort (Category_A)]), DESC,
df[Category_A], MAX(df[Category_A]), DESC
)
)
)


I attempted to modify the formula as discussed, but the results remain inaccurate. Could you please provide guidance or assistance in making the necessary adjustments to achieve the desired outcome?

2 REPLIES 2
Praj8050
Helper I
Helper I

@Sahir_Maharaj  : I implemented the formula you provided, but it's still not producing the correct running total.

Sahir_Maharaj
Super User
Super User

Hello @Praj8050,

 

Can you please try the following:

Units Running Total =
CALCULATE(
    SUM(df[Units]),
    FILTER(
        ALLSELECTED(df),  -- Ensures that date range selection is respected
        df[Sort (Category_A)] <= MAX(df[Sort (Category_A)]) &&  -- Running total up to the current row in Category_A
        df[Category_A] = MAX(df[Category_A]) &&  -- Maintain context for Category_A
        df[Category_B] = MAX(df[Category_B])  -- Maintain context for Category_B in columns
    )
)

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors