How to Build a Slicer with Preset Date Ranges in Power BI
Quick date range selection (e.g. MTD, QTD) with a slicer.
Users often want to filter by preset date ranges such as Last 7 Days, MTD, QTD, or YTD. You can provide a slicer that shows these options and, when one is selected, filters the report to the corresponding period. The approach uses a parameter (field parameter or calculated table) for the labels and a date table or calculated table for the actual date ranges.
Use case
Example: when the user selects Previous 7 Days (e.g. labeled D-1), a bar chart shows the last 7 days of data and a card shows yesterday's value. For Past 15 Days, Past 4 Weeks, or Past 3 Months, the visuals show the corresponding previous period. This is done with a field parameter for the period labels and a calculated table that generates the dates for each period.
Step 1: Create a field parameter
On the Modeling tab, click New Parameter then Fields. Define the date periods and the column that will drive the filter (e.g. Calendar[Date] or Calendar[Fiscal_Week]). Each row in the parameter is a period label and the column to use.
Parameter = {
( "D-1", NAMEOF(Calendar[Date]), "D-1", 1 ),
( "Past 15 Days", NAMEOF(Calendar[Date]), "Past 15 Days", 2 ),
( "Past 4 Weeks", NAMEOF(Calendar[Fiscal_Week]), "Past 4 Weeks", 3 ),
( "Past 3 Months", NAMEOF(Calendar[Fiscal_Month]), "Past 3 Months", 4 )
}Step 2: Create a calculated table for date periods
Create a calculated table that uses DATESINPERIOD (or similar) to build the set of dates for each period type (e.g. last 7 days, last 15 days, last 28 days, last 90 days). Add a Type column that matches the parameter labels (D-1, Past 15 Days, etc.) and a Sort column for display order. This table will be filtered by the parameter selection.
Date_Periods =
UNION(
ADDCOLUMNS(DATESINPERIOD(Calendar[CAL_DT], MAX(Calendar[CAL_DT]), -7, DAY), "Type", "D-1", "Sort", 1),
ADDCOLUMNS(DATESINPERIOD(Calendar[CAL_DT], MAX(Calendar[CAL_DT]), -15, DAY), "Type", "Past 15 Days", "Sort", 2),
ADDCOLUMNS(DATESINPERIOD(Calendar[CAL_DT], MAX(Calendar[CAL_DT]), -28, DAY), "Type", "Past 4 Weeks", "Sort", 3),
ADDCOLUMNS(DATESINPERIOD(Calendar[CAL_DT], MAX(Calendar[CAL_DT]), -90, DAY), "Type", "Past 3 Months", "Sort", 4)
)Step 3: Relationships and measures
Relate the Parameter table to Date_Periods on the Type column. Relate Date_Periods to your Calendar table on the date column; Calendar is related to your fact table. When the user selects a parameter in the slicer, Date_Periods is filtered, which filters Calendar and thus the facts. For special cases (e.g. a card showing only yesterday when D-1 is selected), write a measure that checks SELECTEDVALUE(Parameter[Parameter_Type]) and uses CALCULATE with a filter on the fact date column (e.g. TODAY() - 1) for that case.
Need help with your migration?
Our team can help you design, build, and optimize your Power BI and Fabric solutions.
Get a free assessmentReady to modernize your BI stack?
Stop maintaining legacy workbooks. Start leveraging the full power of the Microsoft Data Platform today.