Skip to main content
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Helper V
Helper V

Add "Last X Days" options to report

My Power BI report feeds off of one table which has, among other fields: 

I use a line chart to plot Reading values over time -- so TimeStamp is on the x axis. 

Since there's a lot of history, users are requesting some shortcut options:

(_) Last 7 days
(_) Last 30 days
(_) Last 90 days
(_) All time

Ideally these option would show up in a single-select slicer. When selected, the data set and visual would filter down to the date range selected. 

I was able to easily implement one such option by adding this measure to my table: 

Last7Days =
VAR _max = MAX(Table1[TimeStamp])
RETURN IF((Table1[TimeStamp] > _max - 7) && Table1[TimeStamp] <= _max, "Last 7 Days")

I can put that in a slicer by itself and when the user clicks the checkbox, the visual filters to show just the last 7 days. 

How can I implement more such options and make them mutually exclusive? 

Super User
Super User

@bvy  You can create a parameter table that has two columns:

* the text labels (ie "Last 7 days")

* the days to filter (ie Today -7) 


Then follow a similar method to this: 

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.

Helpful resources

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.