Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

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:

YTD - 1 =
CALCULATE(
[YTD],
SAMEPERIODLASTYEAR ( 'Date'[Date] ),
'Date'[IsPast] = TRUE
)

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: 

YTD - 1 =
var __prevYear = MAX( 'Date'[Year] ) - 1
RETURN
calculate(sum(Datagrunnlag[Value]),SAMEPERIODLASTYEAR(Datagrunnlag[Dato]),'Date'[Year]=__PrevYear)*1000

Any help is well appreciated!!

2 Replies

  • 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

    • Anonymous's avatar
      Anonymous
      Not 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: