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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.