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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
hargel
Helper I
Helper I

Cummulative sum over all periods keeping filters

Hi!

I've been trying to get a cummulative sum to work. I have a date field, "posting date" and an amount field, "amount". The table, "general ledger" can be filtered by some dimensions. I want to create a measure, "balance" that is the sum of "amount" for all entries up until the selected "posting date". For example if we have a table with month of posting date and "balance", the balance field should show the sum of all entires up until and including each month. I can get this to work, but not if I also want the user to be able to filter the visual or page on "posting date". For example to only show the last three months. I then want the table to show only three months and their balances, but still include all history when calculating the balances. How can this be done? 

 

Thanks,

Martin  

1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi,

I think something like this should work:

RT = 
var maxdate = MAX('Calendar'[Date]) return

CALCULATE(SUM('General Lefger'[Linesum]),
'Calendar'[Date]<= maxdate,
ALL('Calendar'[Date]))

The Key here is to use ALL to remove filter context even if you have e.g. December selected.

Additionally, I recommend checking this article by SQLBI when it comes to running totals: https://www.sqlbi.com/articles/computing-running-totals-in-dax/

I hope this helps and if it does consider accepting this as a solution and giving the post a thumbs up!







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
smpa01
Super User
Super User

@hargel  please provide sample data

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
ValtteriN
Super User
Super User

Hi,

I think something like this should work:

RT = 
var maxdate = MAX('Calendar'[Date]) return

CALCULATE(SUM('General Lefger'[Linesum]),
'Calendar'[Date]<= maxdate,
ALL('Calendar'[Date]))

The Key here is to use ALL to remove filter context even if you have e.g. December selected.

Additionally, I recommend checking this article by SQLBI when it comes to running totals: https://www.sqlbi.com/articles/computing-running-totals-in-dax/

I hope this helps and if it does consider accepting this as a solution and giving the post a thumbs up!







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




This solved it. Or my actual issue was that I did not use a date table but a date column in the fact table. So that was my issue but this is the way of doing it.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.