Forum Discussion
Powereports
Helper I
5 years agoMTD and YTD calculation
@ Power BI users, When I try to use SAMEPERIODLASTYEAR to get MTD of previous year, it returns entire months billed hours sum, rather I was looking for only till current year date sum as in scree...
- 5 years ago
Billed Hours Last Year MTD = var lastNonEmtpyDate = LASTNONBLANK(ALL(Calendar[Date]),[Billed Hours]) return IF(HASONEVALUE('Calendar'[Date]), CALCULATE ( [Billed Hours], SAMEPERIODLASTYEAR(DATESMTD( (Calendar[Date]))), FILTER( ALL(Calendar[Date]), Calendar[Date]<=MAX( 'Billed Hours MTD dax'[Date])) ), CALCULATE([Billed Hours], DATEADD( FILTER(DATESMTD((Calendar[Date])),Calendar[Date]<= lastNonEmtpyDate ), -1, YEAR )))
Powereports
Helper I
5 years agoHi FarhanAhmed,
I guess this time i tried rectifying and closing the brackets but still unable to get there. Any leads would be appreciated.
FarhanAhmed
Community Champion
5 years agoSeems like first calculate missing 1 close bracket and 2nd one has 1 extra bracket
- Powereports5 years ago
Helper I
Thanks for the quick correction Farhan. The Dax works but somehow i get no value populated in the visual as below 😑.. Any insights?
- FarhanAhmed5 years ago
Community Champion
Billed Hours Last Year MTD = var lastNonEmtpyDate = LASTNONBLANK(ALL(Calendar[Date]),[Billed Hours]) return IF(HASONEVALUE('Calendar'[Date]), CALCULATE ( [Billed Hours], SAMEPERIODLASTYEAR(DATESMTD( (Calendar[Date]))), FILTER( ALL(Calendar[Date]), Calendar[Date]<=MAX( 'Billed Hours MTD dax'[Date])) ), CALCULATE([Billed Hours], DATEADD( FILTER(DATESMTD((Calendar[Date])),Calendar[Date]<= lastNonEmtpyDate ), -1, YEAR ))) - Powereports5 years ago
Helper I
Hi FarhanAhmed,
Thankyou for the Magic!! Saved my day!!