Forum Discussion

o59393's avatar
o59393
Post 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 change the visual from date to date hierarchy to visualize just year this happens:

 

 

 

How can I get on the table above the value of 1,435,856,770 for the row 2025 and the column Previous Date OU Demand?

 

Dax is:

Previous Date OU Demand = 

CALCULATE(
        SUM('Append OU Demand'[OU Demand]),
        SAMEPERIODLASTYEAR('Append OU Demand'[Date])
        )

 

Thanks.

  • 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.

     

2 Replies