Forum Discussion

achanikya's avatar
achanikya
Icon for Helper I rankHelper I
4 years ago
Solved

Rolling 12 months

Hi, I used the below measure for calculating Rolling 12 Months, but in data it displayed from january-21 to November-21, Actually it should show Dec-20 to Nov-21. Please refer the below image. Pl...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi achanikya,

    I write a formula to use selection year get the last date from the calendar table and use it as a condition to rolling calculated on the fact table. You can try to use the following measure formula if it is suitable for your requirement:

    Sales amount 12 month =
    //get the selection year from new date table 
    VAR sYear =
        MAX ( 'To Year'[Year] ) //get the last date with selected year from calendar table
    VAR selected =
        CALCULATE (
            MAX ( 'Date'[Date] ),
            FILTER ( ALLSELECTED ( 'Date' ), YEAR ( [Date] ) = sYear )
        )
    RETURN
        //rolling calculation
        CALCULATE (
            [Sales Amount],
            FILTER (
                ALLSELECTED ( 'Fact' ),
                //replace this wiht your fact table
                [Date]
                    >= DATE ( YEAR ( selected ) - 1, MONTH ( selected ), DAY ( selected ) )
                    && [Date] <= selected
            ),
            VALUES ( 'Fact'[System Name] )
        )

    If the above does not help, can you please share a pbix or some dummy data that keep raw data structure with expected results? They should help us clarify your scenario and test to coding formula.

    How to Get Your Question Answered Quickly  

    Regards,

    Xiaoxin Sheng