Forum Discussion

o59393's avatar
o59393
Icon for Post Prodigy rankPost Prodigy
1 year ago
Solved

SAMEPERIODLASTYEAR not working for year

Hi all   I need a dax measure to calculate the previous period values, this could be by year, quarter or month.   The dax I have works well only for month and not for year or Q:     If I...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi o59393 ,

    For the situation you described, you can use the following DAX.

    Previous Date OU Demand = 
    VAR _Date = CALCULATE(SUM('Append OU Demand'[OU Demand]), SAMEPERIODLASTYEAR('Append OU Demand'[Date]))
    VAR _Year = CALCULATE(SUM('Append OU Demand'[OU Demand]), DATEADD('Append OU Demand'[Date].[Date],-1,YEAR))
    RETURN
    IF(SELECTEDVALUE('Append OU Demand'[Date]) = BLANK(),
    _Year,_Date
    )

     

     

     


    Please see the attached pbix for reference.

    Best Regards,
    Dengliang Li

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.