Forum Discussion

JGravelle's avatar
JGravelle
Frequent Visitor
8 months ago
Solved

Sameperiodlastyear on multiple columns

Hi All, I have a table with two dates, and only one date table, and I want the prior year value by shifting both dates to the prior year.   Sample Data: I have a date column with a primary ...
  • V-yubandi-msft's avatar
    V-yubandi-msft
    8 months ago

    Hi JGravelle ,

    Thanks for the clarification. Since you want both the Accounting Date (active relationship) and the Transaction Date (inactive relationship) to shift one year back, relying on SAMEPERIODLASTYEAR alone won’t achieve that. It only affects the active date context.

    A common pattern for this scenario is to shift the calendar using DATEADD, and then activate the Transaction Date relationship inside the calculation.

    VAR ShiftedCalendar =
        DATEADD(dim_date[Date], -1, YEAR)
    RETURN
    CALCULATE(
        SUM(fact_amount[Amount]),
        ShiftedCalendar,
        USERELATIONSHIP(fact_amount[Transaction Date], dim_date[Date])
    )

    This gives you more control over both date contexts. Since every model behaves differently, please test it in your PBIX if the result still doesn’t align with what you expect, feel free to share another screenshot and we can fine tune it together. 

     

    Hope this helps.