Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Timeline Slicer + YTD Measure

Hello, everybody!

I am using the Timeline Slicer in the months and I am having a problem in the current year (2020).

I have filtered the display to only show me the months that have values, that's why it shows me from January to April.

The problem is that when I select from January to April, it compares the whole year of the YTD which is incorrect. I should only consider myself until April:

 


How could I solve this problem in DAX?

Basically I don't want to be added to the accumulated value of the months of the current year that have not yet passed.

Thank you!

Regards!

9 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi 

      I am using the SAMEPERIODYEAR, but I think the problem is the Time Slicer that even if I select from January to April it takes me the whole year.

      If I select from January to March the values in the table are correct:

       

      But when I select from January to April it takes me the whole year and that's the problem I have.

      Thanks

      • amitchandak's avatar
        amitchandak
        Icon for Super User rankSuper User

        Anonymous ,

        Not tested. try like

        Last YTD Sales = = 
        var _max =date(year(today())-1,month(today()),day(today()))
        return
        CALCULATE(SUM(Sales[Sales Amount]),SAMEPERIODLASTYEAR('Date'[Date]),'Date'[Date]<=_max)
  • Anonymous , try like

    YTD Sales = 
    var _max =today()
    return
    CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"),'Date'[Date]<=_max)
    
    
    Last YTD Sales = = 
    var _max =date(year(today())-1,month(today()),day(today()))
    return
    CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"),'Date'[Date]<=_max)