Forum Discussion

ajitsahoo8338's avatar
ajitsahoo8338
Icon for Helper III rankHelper III
1 year ago
Solved

How filter Previous week and All Year Data

Hello Everyone ,   I need help with this isue.I created this to filter the previous week's data and all date data. However, the issue I am facing is that when the selection is 'All Date' it filters...
  • Anonymous's avatar
    Anonymous
    1 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,
    Zhu

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.