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
angelo2022
Frequent Visitor

Problem with Running Totals for Prior Year

Hi, 

I'm struggling with the DAX to calculate the running total for the Prior Year.   The Running total for the current Financial year works fine though.  

 

To get this working I have Two date tables as it always have to show the YTD data regardless of the month I select in the financial year.  These are the results I'm getting.    The Running total for the Prior Year is always blank and only shows up in previous Financial Year.   

 

MonthMeasureMeasure Running TotalMeasure STLYSTLY Running Total
Jul140314031248 
Aug14622865604 
Sep9513816884 
Oct84146571099 
Nov96556221253 
Dec77864001272 
Jan4946894839 
Feb63275261276 
Mar111986451088 
Apr85695011220 
May1253107541339 
Jun1136118901110 

 

This is the Joins to the 2 Date Tables

angelo2022_0-1658286158586.png

 

This is the DAX I'm using: 

 

//Current Year DAX
[MeasureValue]= CALCULATE(SUM('MeasureData'[MeasureResult]))

 

//Current Year Value

[Measure] =
VAR YearSelected = SELECTEDVALUE('DimDate'[Year])
RETURN
CALCULATE([MeasureValue], FILTER(ALL(DimDate), DimDate[Year] = YearSelected))

 

//Current Year Running Total 

[Measure Running Total] = CALCULATE([Measure1], DATESYTD(DimDateYTD[YTDDateValue], "30/06"))


// Prior Year DAX
[Measure STLY] =
VAR YearSelected = SELECTEDVALUE('DimDate'[Year]) - 1
RETURN
CALCULATE([MeasureValue], FILTER(ALL(DimDate), DimDate[Year] = YearSelected))

 

// Prior Year Running Total

[Measure STLY RunningTotal] = CALCULATE([Measure1 STLY], DATESYTD(DimDateYTD[YTDDateValue], "30/06"))

 

Can anyone assist me with this please!! 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@angelo2022 , Try like example

 

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"6/30"))

 

or

 

new column

Day of Year =datediff([Year Start date] , [Date],Day) +1

 

measures

YTD= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank]) && 'Date'[Day of Year] <= Max('Date'[Day of Year]) ))
LYTD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank])-1 && 'Date'[Day of Year] <= Max('Date'[Day of Year])))

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@angelo2022 , Try like example

 

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"6/30"))

 

or

 

new column

Day of Year =datediff([Year Start date] , [Date],Day) +1

 

measures

YTD= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank]) && 'Date'[Day of Year] <= Max('Date'[Day of Year]) ))
LYTD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank])-1 && 'Date'[Day of Year] <= Max('Date'[Day of Year])))

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

Hi @amitchandak ,
Thanks for helping with this one, but could please help me again.   


We have moved to the next financial Year (Jul 2022 to June 2023) but it doesn't seem to calculate a Running Totals for Current and Prior Months for Previous Financial Years unless I add the Year into the visual.  

I had to adjust the Measure Running Total a little
From this: 

//Current Year Running Total 

[Measure Running Total] = CALCULATE([Measure1], DATESYTD(DimDateYTD[YTDDateValue], "30/06"))

 

To this: 

[Measure Running Total] =
VAR IsCurrentFYear = SELECTEDVALUE(DimDate[IsCurrentFY])
RETURN
IF(IsCurrentFYear = TRUE(),
CALCULATE([Measure1], FILTER(DimDateYTD, DimDateYTD[YTDDateValue] <= TODAY())),
CALCULATE([Measure1], DATESYTD(DimDateYTD[YTDDateValue],"30/06")))
//It uses a different calculation if filtering to the current Financial Year. 

I used this for the Running total for STLY
[Measure STLY RunningTotal] =CALCULATE([Measure1 STLY], DATESYTD(DATEADD(DimDateYTD[YTDDateValue], -1,YEAR),"30/6"))

Hope it makes sense and you can help.  
Thanks Angelo

Thanks @amitchandak .  You are the man.... That worked nicely...👍

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.

Top Solution Authors