Forum Discussion

CMOLINA's avatar
CMOLINA
Frequent Visitor
4 years ago
Solved

Compare Year with Numer or Date

hello, I need your help: I have this Calculated Field:  CALCULATE(Sales[Sales USD],FILTER('CALENDAR', 'CALENDAR'[Year]=2022))  this is OK   but when I change for that: Sales CY = ...
  • lukiz84's avatar
    4 years ago

    LASTDATE is calculated per row so for example in the row with 2021-10 the last year is 2021. To make it work the way you want it you have to write it like this:

     

    Sales CY = 
       var CY = CALCULATE(
          YEAR(LASTDATE('Calendar'[Date])),
          ALL(Calendar)
       )
       RETURN
          CALCULATE(
             SUM(Sales[Sales USD]),
             Calendar[Year] = CY
          )