Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Dax for Current Week & Previous Week

Hi, My requirement got changed like below. I have a Date slicer and my week starting from Monday to Sunday. If user selects Today (May 24,2021) then i should be able to see the data only for Curre...
  • mahoneypat's avatar
    5 years ago

    You could add a variable to calculate the most recent monday (relative to the MAX date), and then calculate your measure between the max date and that Monday date.

     

    Weekly =
    VAR _selectedDate =
        MAX ( Table1[DayDate] )
    VAR _endOfWeekDate =
        _selectedDate + 7
            WEEKDAY ( _selectedDate2 )
    VAR lastMonday =
        CALCULATE (
            MAX ( Table1[DayDate] ),
            FILTER (
                ALL ( Table1[DayDate] ),
                Table1[DayDate] <= _selecteddate
                    && WEEKDAY ( Table1[DayDate] ) = 2
            )
        )
    RETURN
        CALCULATE (
            SUM ( Table1[TH] ),
            FILTER (
                ALL ( Table1[DayDate] ),
                Table1[DayDate] <= _endOfWeekDate
                    && Table1[DayDate] >= lastMonday
            )
        )

     

    Pat