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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
SBatHB
Frequent Visitor

How to Calculate Cumulative Running Total by Period, showing multiple years

How can I calculate the running total within a group/ timerange, but do so across multiple years whil using the date slicer?

 

I'm trying to calculate a running total for amounts, but do so in a way that I can compare prior years to each other in the same trending line graph. It is not a YTD calculation, but rather a slice of time (example: March 10 - April 15) that can be determined by the user. I have found ways to do this within a single year, but not across multiple years. So I need a running total within that slice, grouped by the year.

 

Additionally, I have been asked to use the date sliding range slicer, becaues it is so intuitive and easy for the user. So I would have a slicer for 2020, and need to have data from 2019 and 2018 still show up. When I user Power BI's native date filters, the past years are literally filtered out.

 

Here is a link to the Power BI .pbix File with what I have vs. what I'm trying to do. There are a couple of text boxes in there with notes.

https://drive.google.com/open?id=1sVBNi51i4h1KV3cZhnYeIRo7byRMERfS 

 

Thank you!

1 ACCEPTED SOLUTION

Hi @SBatHB ,

 

I've created this file as an example: Download PBIX 

 

Please, check if it helps.

 

If you consider it as a solution, please mark it as a solution, so we can help others.

 

Ricardo



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

Proud to be a Super User!



View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @SBatHB,

If you want your date slicer works as a 'selector' and not directly filter on your records, please not use date field which related to fact table fields.

You can create a new table with date field as the source of slicer, then add a condition in your dax formula to compare with current date fields and select date ranges.

 

Measure =
VAR currDate =
    MAX ( 'Fact'[Date] )
RETURN
    CALCULATE (
        'Fact'[Amount],
        FILTER (
            ALLSELECTED ( 'Fact' ),
            YEAR ( 'Fact'[Date] ) = YEAR ( currDate )
                && 'Fact'[Date] <= currDate
                && 'Fact'[Date] IN ALLSELECTED ( Selector[Date] )
        )
    )

 

Regards,

Xiaoxin Sheng

Hi @SBatHB ,

 

I've created this file as an example: Download PBIX 

 

Please, check if it helps.

 

If you consider it as a solution, please mark it as a solution, so we can help others.

 

Ricardo



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

Proud to be a Super User!



For those lokking at this, the solution in the Power BI workbook provided by camargos88 is here:

Running Total = 
VAR _dtMin = CALCULATE(MINX(Sheet1, Sheet1[Date]), ALLSELECTED())
VAR _dtMax = CALCULATE(MAXX(Sheet1, Sheet1[Date]), ALLSELECTED())
VAR _tblCross = SELECTCOLUMNS(ADDCOLUMNS(CROSSJOIN(DATESBETWEEN(Sheet1[Date], _dtMin, _dtMax), VALUES(Sheet1[Date].[Year])), "N_DATE", DATE(Sheet1[Date].[Year], MONTH(Sheet1[Date]), DAY(Sheet1[Date]))), "N_DATE", [N_DATE])
VAR _currentDate = SELECTEDVALUE(Dates[Date])
VAR _minDate = CALCULATE(MIN(Dates[Date]), FILTER(ALL(Dates), Dates[Date] in _tblCross && Dates[Date].[Year] = YEAR(_currentDate)))
RETURN SUMX(FILTER(Dates, Dates[Date] in _tblCross), CALCULATE(SUM(Sheet1[Amount]), FILTER(ALL(Sheet1[Date]), Sheet1[Date] >= _minDate && Sheet1[Date] <= MAX(Dates[Date]))))

 

I don't fully understand it, but it looks to use variables to

  1. Calculate the min and max dates in a range
  2. Create a date table as a variable with all dates between that min and max range
  3. Figure out the current year
  4. Find the Cumulative sum within the min and max date, using ALL in the filter to ignore the sected / current year filter.

 

So it's essentially finding a date range, and then calculating between those. I'm not sure, but it looks like the lack of relationship between the date table and my Fact table could be important.

 

Thanks for providing this solution!

Greg_Deckler
Community Champion
Community Champion

By using ALL or ALLEXCEPT or REMOVEFILTERS. 

 

See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

ALL and ALLEXCEPT were both solutions that I came across, but I must be calculating the running total incorrectly for them to properly work. Applicable in other DAX functions though; thanks!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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