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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Sburi2
New Member

Running Total Breaks when Adding Top N

Hello!

 

I'm trying to obtain obtain a running total. I have the DAX working:

 

 

Running Total = 

VAR thisCategory = [sum Total Monthly Cost]

VAR RunningTotal_ThisCategory = 
    CALCULATE(
        [sum Total Monthly Cost],
        FILTER(ALLSELECTED(tbApptioAppCosts[App Name]), [sum Total Monthly Cost]>=thisCategory)
    )

RETURN
RunningTotal_ThisCategory

 

 

 

However, when I filter the visual to Top 10 by App Name, the running totals fails to be cumulative.

Would really appreciate help understanding what is happening under-the-hood so I can resolve issues like this in the future myself.

 

This is what I want

Correct ExpectationTotalCumulative Total
Cat A300300
Cat B200500
Cat C100600

 

This is what I'm getting

What's HappeningTotalCumulative Total
Cat A300300
Cat B200200
Cat C100100

 

Thank you!

2 ACCEPTED SOLUTIONS

@Sburi2 

I made a sample file. as you can see, I filtered by top 3, and still, the result is correct. In your initial posting of the question, you had used ALLSELECTED when you calculated the all appname total, you should use ALL. check my formula below: I attached the file as well.



Cummulative = 
var __current = [Total Sales]
var __all = CALCULATE( [Total Sales] , ALLSELECTED(financials[Product]))
var __cumm = 

    CALCULATE(
        [Total Sales],
        FILTER(
            ALLSELECTED(financials[Product]),
            [Total Sales] >= __current
        )
    )
return
DIVIDE( __cumm , __all )

Fowmy_0-1626456936832.png

 



 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

@Sburi2 

When you posted the question initially, I noticed that you had used ALL instead of ALLSELECTED. It was one reason for the incorrect results when you applied TOPn filter. Apart from that you also had applied some other filters. 

ar __all = CALCULATE( [Total Sales] , ALLSELECTED(financials[Product]))

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

9 REPLIES 9
Fowmy
Super User
Super User

@Sburi2 

Your formula should work, can you re-recheck ?





Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thanks @Fowmy , good to know I'm not a complete dunce. It *does* work as long as I don't have Top N filter applied on [App Name] by [Total Monthly Cost]. Once I apply the filter however, it no longer calculates the running total.

@Sburi2 

I made a sample file. as you can see, I filtered by top 3, and still, the result is correct. In your initial posting of the question, you had used ALLSELECTED when you calculated the all appname total, you should use ALL. check my formula below: I attached the file as well.



Cummulative = 
var __current = [Total Sales]
var __all = CALCULATE( [Total Sales] , ALLSELECTED(financials[Product]))
var __cumm = 

    CALCULATE(
        [Total Sales],
        FILTER(
            ALLSELECTED(financials[Product]),
            [Total Sales] >= __current
        )
    )
return
DIVIDE( __cumm , __all )

Fowmy_0-1626456936832.png

 



 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

That's so odd... I open up your file and it works. I open up my file and it doesn't. I compare the DAX formulas and they are functionally the same. I'm not sure where I'm going wrong.

 

I also just noticed that it actually is performing a cumulative count, but only when the previous numbers exactly equal the current numbers. I'm not using =, I'm using >=... not sure what's wrong. 

@Sburi2 

 

I am not sure how your model is setup. 

Share your dax formula to check. 

you can also attach a sample file like I did, save it in OneDrive or any other cloud location and share the link

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Same formula as before essentially. Would share the file but the data is confidential of course and if I simplify it I'll end up with a (less clean) version of your file 🙂

 

I did find out what was causing the issue but not why. I have another filter on the page on the column with the monthly cost. I'm filtering out things that are = 0. For some reason, having this filter applied breaks the cumulative function.

@Sburi2 

Hope it works fine now?

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Indeed, thanks! Just wish I knew what was wrong!

@Sburi2 

When you posted the question initially, I noticed that you had used ALL instead of ALLSELECTED. It was one reason for the incorrect results when you applied TOPn filter. Apart from that you also had applied some other filters. 

ar __all = CALCULATE( [Total Sales] , ALLSELECTED(financials[Product]))

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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
Top Kudoed Authors