Forum Discussion

MarcoT's avatar
MarcoT
Frequent Visitor
4 years ago
Solved

SAMEPERIODLASTYEAR not working on previous year

Hi, I'm pretty new to PowerBI and I appreciate this forum to share experiences.

I've a problem with a measure not displaying the correct value. I've a fact table called Summary in which I've the field [Prepared Quantity] on wich I've created this measure:


Deliberated Lines TOT = CALCULATE(SUM('Summary'[Prepared Quantity]), GROUPBY('Summary','Summary'[Planned Delivery Date],'Summary'[Shipment Type],'Summary'[FLG Prep]))

 

where [Planned Delivery Date] is a non-unique field of type date.

What I would like to do is displaying the same value but one year before the selected date or the date in the visual row. I tried to use the SAMEPERIODLASTYEAR with [Planned Delivery Date] but it gave me an error because the date rows are not unique. So I added a calendar table in order to do that and I linked the [Planned Delivery Date Id] field to the calendar key of the calendar dimension. After that I've created this measure:

 


Deliberated Lines TOT Previous Year = CALCULATE('Summary'[Deliberated Lines TOT],ALL('Calendar'[Date Value]),SAMEPERIODLASTYEAR('Calendar'[Date Value])) 

 

but it shows me the same value of the [Deliberated Lines TOT] measure.

Here's a screenshot:

 

What I'm doing wrong?

Thanks in advance

 

  • MarcoT 

    For Week in Year Number make sure tgat you select "Do not summarize" also make sure that 'Calendar' is marked as date table with Date Value as the date column. Then the following should technically work. 

    Deliberated Lines TOT Previous Year =
    CALCULATE (
        'Summary'[Deliberated Lines TOT],
        ALL ( 'Calendar' ),
        SAMEPERIODLASTYEAR ( 'Calendar'[Date Value] )
    )

3 Replies

  • tamerj1's avatar
    tamerj1
    Icon for Community Champion rankCommunity Champion

    Hi MarcoT 

    In your table visual, Instead of Planned Delivery Date please use 'Calendar'[Date] and instead of Week Planned Delivery Date use 'Calender'[Week Number] 

    • MarcoT's avatar
      MarcoT
      Frequent Visitor

      Hi, I've done it but now but unfortunately it shows no results. Here's a screenshot:

       

      • tamerj1's avatar
        tamerj1
        Icon for Community Champion rankCommunity Champion

        MarcoT 

        For Week in Year Number make sure tgat you select "Do not summarize" also make sure that 'Calendar' is marked as date table with Date Value as the date column. Then the following should technically work. 

        Deliberated Lines TOT Previous Year =
        CALCULATE (
            'Summary'[Deliberated Lines TOT],
            ALL ( 'Calendar' ),
            SAMEPERIODLASTYEAR ( 'Calendar'[Date Value] )
        )