Forum Discussion

kjanderson2's avatar
kjanderson2
Regular Visitor
6 years ago
Solved

Pulling a Rolling Average - Dynamic Time

Hello!   I'm seeing a lot of posts on this, however I'm not finding a solution for my specific situation. I've got 3 relevant columns : Date, Item, Sales. I want an average of the last 6 weeks sale...
  • v-juanli-msft's avatar
    6 years ago

    Hi kjanderson2 

    Create calculated columns

    year-week = FORMAT([date],"yyyy-ww")

    Create measures

    sum per week =
    CALCULATE (
        SUM ( Sheet3[value] ),
        FILTER (
            ALLSELECTED ( Sheet3 ),
            Sheet3[item]
                = MAX ( Sheet3[item] )
                && Sheet3[year-week]
                    = MAX ( Sheet3[year-week] )
        )
    )
    
    sum last 6 weeks =
    CALCULATE (
        SUM ( Sheet3[value] ),
        FILTER (
            ALLSELECTED ( Sheet3 ),
            DATEDIFF (
                Sheet3[date],
                TODAY (),
                WEEK
            ) < 6
                && Sheet3[item]
                    = MAX ( Sheet3[item] )
        )
    )
    
    
    count_last6weeks =
    CALCULATE (
        DISTINCTCOUNT ( Sheet3[year-week] ),
        FILTER (
            ALLSELECTED ( Sheet3 ),
            DATEDIFF (
                Sheet3[date],
                TODAY (),
                WEEK
            ) < 6
                && Sheet3[item]
                    = MAX ( Sheet3[item] )
                && [sum per week] <> 0
        )
    )
    
    average = [sum last 6 weeks]/[count_last6weeks]
    

    If there are no missing data

    If there is missing data,

    Best Regards
    Maggie
    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.