powerbipowerbi-custom-visuals

How to create a custom date period slicer


Is it possible to have single selection radio buttons slicer that would filter by Today() - 7 days, Today() - 30 days and Today() - 60 days? So, to plot the last 7 days values, 30 days values or 60 days values. I'm able to single select by Quarters but instead of quarters use a range of days based on today's date? I tried filters but didn't get it to work.

enter image description here

Thank you for your help.


Solution

    1. Add a calculated table:
    Date Periods = 
    UNION(
        ADDCOLUMNS(
            CALENDAR(TODAY() - 7, TODAY()),
            "Period", "Last 7 days",
            "Sort", 1
        ),
        ADDCOLUMNS(
            CALENDAR(TODAY() - 30, TODAY()),
            "Period", "Last 30 days",
            "Sort", 2
        ),
        ADDCOLUMNS(
            CALENDAR(TODAY() - 60, TODAY()),
            "Period", "Last 60 days",
            "Sort", 3
        )
    )
    
    1. Sort the Period column by the Sort column
    2. Create a bi-directional relationship between 'Date Periods'[Date] and your days
    3. Add 'Date Periods'[Period] to a slicer and set the selection settings to Single select

    The result should look like this:

    enter image description here

    enter image description here