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 relationship to the accounting date, and an inactive relationship to the transaction date.

Measures:

Total Amount (Transaction Date) = CALCULATE(SUM(fact_amount[Amount]), USERELATIONSHIP(fact_amount[Transaction Date], dim_date[Date]))
Total Amount (PY) (Transaction Date) = CALCULATE([Total Amount (Transaction Date)], SAMEPERIODLASTYEAR(dim_date[Date]))
 
What I want is if I apply a filter to the accounting date, for the accounting date to also be same period prior year.


Thanks in advance for the help.

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

6 Replies

  • Hi JGravelle 

    SAMEPERIODLASTYEAR shifts the dates a year back relative to the current row date - not a year forward. Try using DATEADD instead.

     

     

    • JGravelle's avatar
      JGravelle
      Frequent Visitor

      I'm sorry I don't think I was clear enough in the request.

      I want the 12/2/2025, Prior year number to be 1100 which is the same transaction date in the prior year.  but I also want the accounting period to shift a year as well, so accounting period 2025.

      I want both date periods to shift a year prior.

      • V-yubandi-msft's avatar
        V-yubandi-msft
        Icon for Community Support rankCommunity Support

        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.

  • Hi,

    Try these measures

    Total amount (accounting date) = sum(fact_amount[amount])

    Total Amount (PY) (Accounting Date) = CALCULATE([Total amount (accounting date)]SAMEPERIODLASTYEAR(dim_date[Date]))

  • Hi JGravelle ,

    If you haven’t had a chance to review my response yet, please do so and let me know if you need any additional details.

     

    Thank you.

  • Hi JGravelle ,

    May I know if your issue is resolved? If you need any additional details or assistance, please let us know.


    Thank you