Forum Discussion
How filter Previous week and All Year Data
- Anonymous1 year ago
Thanks for the replies from DataNinja777.
Hi ajitsahoo8338 ,
Based on your description, I created two more tables, the Date table and the Slicer table with fields as slicers:
Create two measures:
Measure = VAR CurrentDate = TODAY() VAR LastSunday = (CurrentDate - WEEKDAY(CurrentDate, 1))-6 -- Get the last Sunday VAR LastSaturday = CurrentDate - WEEKDAY(CurrentDate, 1) -- Saturday of the previous week VAR DateValue = MAX('DateTable'[Date]) RETURN IF( SELECTEDVALUE('Slicer'[SlicerValue]) = "All Date", "All Date", IF( DateValue >= LastSunday && DateValue <= LastSaturday, "Previous Week", "All Date" ) )Filter = SWITCH(SELECTEDVALUE('Slicer'[SlicerValue]), "All Date",1, "Previous Week",IF(MAX('DateTable'[Date])>=MIN('Date'[Date])&&MAX('DateTable'[Date])<=MAX('Date'[Date]),1,0))Filter visual using Filter measure:
Result:
Best Regards,
ZhuIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for the replies from DataNinja777.
Hi ajitsahoo8338 ,
Based on your description, I created two more tables, the Date table and the Slicer table with fields as slicers:
Create two measures:
Measure =
VAR CurrentDate = TODAY()
VAR LastSunday = (CurrentDate - WEEKDAY(CurrentDate, 1))-6 -- Get the last Sunday
VAR LastSaturday = CurrentDate - WEEKDAY(CurrentDate, 1) -- Saturday of the previous week
VAR DateValue = MAX('DateTable'[Date])
RETURN
IF(
SELECTEDVALUE('Slicer'[SlicerValue]) = "All Date",
"All Date",
IF(
DateValue >= LastSunday && DateValue <= LastSaturday,
"Previous Week",
"All Date"
)
)Filter =
SWITCH(SELECTEDVALUE('Slicer'[SlicerValue]),
"All Date",1,
"Previous Week",IF(MAX('DateTable'[Date])>=MIN('Date'[Date])&&MAX('DateTable'[Date])<=MAX('Date'[Date]),1,0))
Filter visual using Filter measure:
Result:
Best Regards,
Zhu
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.