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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

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
➤ The Tech Journal Blog: https://sahirmaharaj.tech
➤ About: https://sahirmaharaj.com/about.html
➤ Email: [email protected]
➤ 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
Fabric Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.