Forum Discussion

ADSL's avatar
ADSL
Icon for Post Prodigy rankPost Prodigy
2 years ago
Solved

Showing Last 03 Month Average Sales Rolling

Hi BI Community Team,   As per purpose, we want to see and track only top 10 customers only that average purchased at least 03 month with high amount. Then I have search and found this dax: Top10...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi ADSL 

     

    Please try this:

    Here I create a Measure:

    MEASURE =
    VAR _Slicer_Month =
        MONTH ( MAX ( 'Calendar'[Date] ) )
    VAR _Slicer_Year =
        YEAR ( MAX ( 'Calendar'[Date] ) )
    VAR __Month =
        SUMMARIZE (
            SELECTCOLUMNS (
                CALENDAR (
                    DATE ( _Slicer_Year, _Slicer_Month - 3, 1 ),
                    DATE ( _Slicer_Year, _Slicer_Month - 1, 1 )
                ),
                "_Month", FORMAT ( [Date], "YYYY-mm" )
            ),
            [_Month]
        )
    VAR _vtable =
        SUMMARIZE (
            ALL ( 'Sales Order' ),
            Customers[Customer Name],
            'Sales Order'[Month],
            "_SUMSales", SUM ( 'Sales Order'[Sales_Amt] )
        )
    VAR _vtable2 =
        SUMMARIZE (
            _vtable,
            'Customers'[Customer Name],
            "_AVG",
                VAR _currentName =
                    SELECTEDVALUE ( Customers[Customer Name] )
                RETURN
                    AVERAGEX (
                        FILTER ( _vtable, [Month] IN __Month && [Customer Name] = _currentName ),
                        [_SUMSales]
                    )
        )
    RETURN
        IF (
            SELECTEDVALUE ( Customers[Customer Name] )
                IN SELECTCOLUMNS ( TOPN ( 10, _vtable2, [_AVG], DESC ), [Customer Name] ),
            SUM ( 'Sales Order'[Sales_Amt] )
        )
    

    Add it to the table visual, the result is as follow:

     

     

    Best Regards

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