Forum Discussion
DAX help - Last year YTD is wrong
Hello,
I'm currently struggling with the YTD - 1 measure, as it keeps giving me the wrong number. The DAX I'm currently using is this:
These are the values I'm getting:
And these are the values I should have gotten (it's in '000):
As you can see, my YTD is correct, however my YTD - 1 is pretty off. I can't seem to find what I'm doing wrong.
Using this DAX gave me the exact same, wrong YTD - 1:
Any help is well appreciated!!
2 Replies
- amitchandak
Super User
Anonymous , Try with help from date table , marked as date table
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))YTD QTY forced=
var _max = today()
return
if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),DATESYTD('Date'[Date])), blank())
//or
//calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),filter('Date','Date'[Date]<=_max))
//calculate(TOTALYTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))LYTD QTY forced=
var _max = date(year(today())-1,month(today()),day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA- AnonymousNot applicable
Hello amitchandak. The YTD dax worked, but the YTD - 1, although a different number to what I got with my own YTD - 1 DAX. is still giving me the wrong number.
Also, I think there's something wrong as the number won't appear in a chart: