Forum Discussion

umpoohg's avatar
umpoohg
Helper I
9 years ago
Solved

SAMEPERIODLASTYEAR WITH YTD

Hello all,   I am fairly new to Power BI, and I have been tasked with creating some Sales report, specifically a report with the YTD, MTD, QTD and well as the sameperiodlastyear for each.  I have c...
  • jblackshear's avatar
    jblackshear
    9 years ago

    (I'm still pretty new at this myself but I encountered this situation)

    I think your previous YTD is using the same context as the current YTD, or maybe you have a date filter on the whole matrix to report a specific year, so it isn't finding any data. Here is the thread with the problem I had and the solution.

     

    SAMEPERIODLASTYEAR with a year filter

     

    What I ended up doing was this (this is from my own solution, I haven't tried to fit it to yours)

    RevenueLastYTD = CALCULATE([RevenueYTD], FILTER(ALL(Dates), Dates[CalendarYear]=MAX(Dates[CalendarYear])-1), SAMEPERIODLASTYEAR(Dates[Date]))

     

    The key is using CALCULATE and FILTER. FILTER(ALL(Dates), ...) first opens up the dates context to use all dates again (because it may be currently set at a specific year, either because of a date filter on the whole matrix, or because of the row it is on). Then the next part of the filter statement sets a new filter for the previous year. I'm not entirely sure if that part is necessary since I'm calling SAMEPERIODLASTYEAR. I first did this several months ago and haven't worked with it much since then.

     

    But take a look at using FILTER to open up the context in your previous year calculation.