Forum Discussion

trishd1223's avatar
trishd1223
Frequent Visitor
3 years ago

Calculate % chg for Prior Period

Hi - I need to calculate % change for prior period.  I was able to do that for % chg vs Prior year, because I have two different columns - $ Sales and $ Sales Year Ago.  However, I don't have the $ Sales Prior Period column.  I have 12 different monthly periods and a $ Sales column.  So for example, I'd like to know the % Change in $ Sales from the 4 week ending 1/28/23 vs 12/31/22.  Any ideas how I would do this?  Thanks! 

 

 

   

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi trishd1223 ,

     

    Please try this measure.

     

    Measure = 
    VAR _cur_period = MAX('Table2'[Period])
    VAR _pre_period = CALCULATE(MAX('Table2'[Period]),'Table2'[Period]<_cur_period)
    VAR _before_pre_period = CALCULATE(MAX('Table2'[Period]),'Table2'[Period]<_pre_period)
    VAR _sale1 = CALCULATE(SUM('Table1'[Sales]),'Table1'[Date] > _before_pre_period && 'Table1'[Date] <= _pre_period)
    VAR _sale2 = CALCULATE(SUM('Table1'[Sales]),'Table1'[Date] > _pre_period && 'Table1'[Date] <= _cur_period)
    VAR _result = DIVIDE(_sale2-_sale1,_sale1)
    RETURN
    _result

     

     

    Comparing different time periods – DAX Patterns

    Week-related calculations – DAX Patterns

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum