Forum Discussion

sivaadityat's avatar
sivaadityat
Frequent Visitor
2 years ago
Solved

Rolling 12 months DAX calculation

Hello,

 

Good Day!

 

I have a requirement to visualize rolling 12 months(last 12 monts from selected in filter) data in bar graph. Please give me a suggetion how can I acheive DAX for that.

 

Please note that, system recognized dates are not available in my data.

 

Here is the sample data:

YearMonthValue
20221100
20222101
20223102
20224103
20225104
20226105
20227106
20228107
20229108
202210109
202211110
202212111
20231112
20232113
20233114
20234115
20235116
20236117
20237118
20238119
20239120
202310121
202311122
202312123
20241124
20242125
20243126
20244127
20245128
20246129
20247130
20248131
20249132
202410133
202411134
202412135
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi sivaadityat 

    You can refer to the following solution.

    1.Create a slicer table

    Slicer = SUMMARIZE('Table',[Year],'Table'[Month])

    2.Create a measure

    Measure =
    VAR a =
        DATE ( MAX ( 'Slicer'[Year] ), MAX ( 'Slicer'[Month] ), 1 )
    VAR b =
        EOMONTH ( a, -12 )
    RETURN
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                'Table',
                EOMONTH ( DATE ( MAX ( 'Table'[Year] ), MAX ( 'Table'[Month] ), 1 ), 0 ) >= b
                    && EOMONTH ( DATE ( MAX ( 'Table'[Year] ), MAX ( 'Table'[Month] ), 1 ), 0 )
                        < EOMONTH ( a, 0 )
            )
        )
    

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 Replies

  • Your sample data is not usable.

     

    You also need to define what you mean by "last 12 months"  - does that include the currently selected month?

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi sivaadityat 

    You can refer to the following solution.

    1.Create a slicer table

    Slicer = SUMMARIZE('Table',[Year],'Table'[Month])

    2.Create a measure

    Measure =
    VAR a =
        DATE ( MAX ( 'Slicer'[Year] ), MAX ( 'Slicer'[Month] ), 1 )
    VAR b =
        EOMONTH ( a, -12 )
    RETURN
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                'Table',
                EOMONTH ( DATE ( MAX ( 'Table'[Year] ), MAX ( 'Table'[Month] ), 1 ), 0 ) >= b
                    && EOMONTH ( DATE ( MAX ( 'Table'[Year] ), MAX ( 'Table'[Month] ), 1 ), 0 )
                        < EOMONTH ( a, 0 )
            )
        )
    

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.