Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Dynamic total sales with moving week

Hello datanuts! v-lionel-msft    I need help to create some DAX that will help me to sumarize the following data in a proper way. I receive a weekly report with 4 weeks history of sales. If a sele...
  • Anonymous's avatar
    Anonymous
    6 years ago

    HI Anonymous,

    So you mean you want to display selected report week and the first week of each row? If this is a case, you can refer to following measure formula:

    Measure =
    VAR currRW =
        MAX ( Table[REPORT WEEK] )
    VAR currSW =
        MAX ( Table[SALES WEEK] )
    VAR week =
        CALCULATETABLE (
            VALUES ( Table[SALES WEEK] ),
            FILTER ( ALLSELECTED ( Table ), [REPORT WEEK] <= MAX ( Selector[REPORT WEEK] ) ),
            VALUES ( Table[REPORT WEEK] )
        )
    RETURN
        IF (
            currRW IN ALLSELECTED ( 'Selector'[REPORT WEEK] )
                || currSW = MINX ( week, [SALES WEEK] )
                    && ISFILTERED ( Table[SALES WEEK] ),
            CALCULATE (
                SUM ( Table[SALES TOTAL] ),
                ALLSELECTED ( Table ),
                VALUES ( Table[REPORT WEEK] ),
                VALUES ( Table[SALES WEEK] )
            )
        )
    

    Regards,

    Xiaoxin Sheng