Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Sort Months ascending starting with current month

I inherited a calendar table in this model with a nice set of options. The request I received is that they want to see rolling 12 months but also compare the previous. So we would be comparing Jan 20...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Figured it out!

    Month Sort =
    IF (
    MONTH (
    CALCULATE ( MAX ( 'Calendar'[Date] ), 'Calendar'[CurrentDayOffset] = 0 )
    )
    < MONTH ( 'Calendar'[Date] ),
    12
    - ABS (
    MONTH (
    CALCULATE ( MAX ( 'Calendar'[Date] ), 'Calendar'[CurrentDayOffset] = 0 )
    )
    )
    - MONTH ( 'Calendar'[Date] ) + 1,
    MONTH (
    CALCULATE ( MAX ( 'Calendar'[Date] ), 'Calendar'[CurrentDayOffset] = 0 )
    )
    - MONTH ( 'Calendar'[Date] ) + 1
    )


    I was able to come up with a mathematical formula and then just had to convert that into DAX.