Forum Discussion

rogerdea's avatar
rogerdea
Helper IV
1 year ago
Solved

Creating filter where date value can fall into different buckets

I want to create a filter for "next 7 days" and also "next 14 days", where a date might fall into both categories.  Been trying to do this a while without success, i had the following code as an appr...
  • johnt75's avatar
    1 year ago

    Create a new table like

    Time Period Slicer =
    SELECTCOLUMNS (
        UNION (
            GENERATE (
                { "Next 7 Days" },
                DATESINPERIOD ( dim_date_bi[date], TODAY (), 7, DAY )
            ),
            GENERATE (
                { "Next 14 Days" },
                DATESINPERIOD ( dim_date_bi[date], TODAY (), 14, DAY )
            )
        ),
        "Period", [Value1],
        "Date", [Value2]
    )
    

    Create a many-to-many relationship from the new table to your date table, single direction so that the new table filters date, not the other way around.

    Use the new table in your slicer.