Forum Discussion

WILLIAMSKEY3's avatar
WILLIAMSKEY3
Frequent Visitor
1 year ago
Solved

Measure not working when multiple weeks are selected in slicer

Hi, I created a below measure to calculate the previous week sales. It is working fine when I am selecting a single week. But when more than one week is selected, it is not adding up. Example. I s...
  • WILLIAMSKEY3's avatar
    1 year ago

    I was able to get a solution from another source, as the one proposed got me close to my solution but not quite there. Below is my new measure that gives the sum of total sales if one week is selected, or if more than one week is selected.

    TTL PREVIOUS SALES  =
    VAR SelectedWeeks = VALUES('DATES'[WEEK])
    VAR SelectedYear = SELECTEDVALUE('DATES'[YEAR])
    VAR LastYear = SelectedYear - 1

    VAR ShiftedSales =
        SUMX(
            SelectedWeeks,
            VAR CurrentWeek = [WEEK]
            VAR ShiftedWeek = CurrentWeek + 1

            RETURN
                CALCULATE(
                    [TTL SALES ],
                    FILTER(
                        ALL('DATES'),
                        'DATES'[WEEK] = ShiftedWeek &&
                        'DATES'[YEAR] = LastYear
                    )
                )
        )

    RETURN
        ShiftedSales