Forum Discussion

Elisa_Costanza's avatar
1 year ago
Solved

New Measure with Rolling 12 Month

  Good afternoon everyone, I need your support to calculate a DAX measure in a Power BI report. I have to create a line chart in Power BI, where: On the X-axis I need to place the time interval...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Elisa_Costanza ,
    Thank you rohit1991  and rajendraongole1  for the helpful response!

    Upon reviewing the provided information,I tried to recreate it locally with the sample data.

    1.Create Disconnected Slicer Table using below:

    Disconnected_Calendar =
    SELECTCOLUMNS(
        Calendar,
        "YearMonthDate", [YearMonthDate]
    )



    2.Create the F100 Rolling 12M Measure using below:

    F100 Rolling 12M (%) =
    VAR CurrentYM = MAX(Calendar[YearMonthDate]) -- <- this now uses the X-axis value
    VAR MinYM = EDATE(CurrentYM, -11)

    VAR SelectedMaxYM = MAX(Disconnected_Calendar[YearMonthDate]) -- from slicer

    RETURN
    IF (
        CurrentYM <= SelectedMaxYM && CurrentYM >= MinYM,
        VAR DefectCount =
            CALCULATE(
                DISTINCTCOUNT(Fact[key_fail]),
                FILTER(
                    ALL(Calendar),
                    Calendar[YearMonthDate] >= EDATE(CurrentYM, -11) &&
                    Calendar[YearMonthDate] <= CurrentYM
                )
            )

        VAR VINCount =
            CALCULATE(
                SUM(Fact[activity_rate]),
                FILTER(
                    ALL(Calendar),
                    Calendar[YearMonthDate] >= EDATE(CurrentYM, -11) &&
                    Calendar[YearMonthDate] <= CurrentYM
                )
            )

        RETURN DIVIDE(DefectCount, VINCount, BLANK()),
        BLANK()
    )

    Please refer the attached sceenshot and the file for your reference.


    If this solution meets your requiremnet,consider accept it as solution.

    Thank you .

    Regards,
    Pallavi.