Forum Discussion

Sara_J's avatar
Sara_J
Frequent Visitor
4 years ago
Solved

Rolling average and dax code for other excel formulas

Hi,   I have 3 tables :  Dim_Weeks, Fact1 and Fact2 joined by wk_num Need dax code for the F,G,H Fact 1:                                       Fact2: col-   A B   C D row Wk_num vo...
  • v-chenwuz-msft's avatar
    v-chenwuz-msft
    4 years ago

    Hi Sara_J ,

    % vs F1F2 = divide(RELATED(Table2[vol3]),[vol1],0)
    
    rolling last 4 weeks =
    AVERAGEX (
        FILTER (
            'Table1',
            [Wk_num_1] <= EARLIER ( Table1[Wk_num_1] )
                && [Wk_num_1]
                    >= EARLIER ( Table1[Wk_num_1] ) - 3
        ),
        [% vs F1F2]
    )
    
    Proj% =
    DIVIDE (
        DIVIDE ( RELATED ( Table2[vol3] ), [rolling last 4 weeks] ) - [vol2],
        [vol2],
        0
    )
    
    Projected =
    IF (
        [vol1] = 0,
        DIVIDE ( RELATED ( Table2[vol3] ), [rolling last 4 weeks] ),
        IF (
            AND (
                [vol1] > 0,
                CALCULATE (
                    MAX ( 'Table1'[vol1] ),
                    FILTER ( 'Table1', [Wk_num_1] = EARLIER ( Table1[Wk_num_1] ) + 1 )
                ) = 0
            ),
            [vol1],
            BLANK ()
        )
    )
    

    Result:

     

    Pbix in the end you can refer.

    Best Regards

    Community Support Team _ chenwu zhu

     

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