Forum Discussion

Walt1010's avatar
Walt1010
Helper V
1 year ago
Solved

Structuring a rolling 12 month comparative analysis

I have a table of sickness leave events, including values for sickness date and sickness type. I would like to provide several charts and tables that compare the last 12 months data against the previ...
  • mark_endicott's avatar
    1 year ago

    Walt1010 - if you are looking to compare days against the exact point in time 12 months previously you can use DATEADD inside CALCULATE:

     

    CALCULATE( [Measure], DATEADD( 'DateTable'[Date], -1, YEAR ) )

     

    If you'd like to do something similar, but with a range of dates SAMEPERIODLASTYEAR might be more appropriate: https://dax.guide/sameperiodlastyear/ or DATESINPERIOD could help if this is more complex: https://dax.guide/datesinperiod/ 

     

    If you'd like to compare against a rolling average of the last 12 months, you can either use a visual calculation: https://www.youtube.com/watch?v=McRGFB55_kI or a DAX measure: https://www.sqlbi.com/articles/rolling-12-months-average-in-dax/ 

     

    Ultimately which function you use will be determined by the type of comparison you are trying to do. 

     

    If I answered your question please mark my post as the solution, it helps others with the same challenge find the answer!

  • v-echaithra's avatar
    1 year ago

    Hi Walt1010 ,

    Thank you for reaching out to Microsoft Community.

    As per the information provided i understand that you want to compare sickness Leave over the Last 12 Months with the Previous 12 Months .

    Make sure you have a Date Table with a continuous date range and a relationship exists between DateTable[Date] and Sickness[Sickness Date].

     

    Sickness Count = COUNTROWS('Sickness')

     

    Sickness Count L12M =

    CALCULATE( [Sickness Count], DATESINPERIOD( 'DateTable'[Date], MAX('DateTable'[Date]), -12, MONTH ) )

     

    Sickness Count P12M = CALCULATE( [Sickness Count], DATESINPERIOD( 'DateTable'[Date], EDATE(MAX('DateTable'[Date]), -12), -12, MONTH ) )


    If this helped, please mark it as the solution so others can benefit too. And if you found it useful, kudos are always appreciated.

    Thanks,
    Chaithra E.