Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.
My report has data going back to 2023-07-01. I am hoping I can adjust the slicer to default to showing the last 30 days worth of data, including yesterday, but not today. I am hoping the slicer has this defaulted when the user views the report and the user does not have to adjust the slicer to the most recent data.
In the image of the slicer above, the user can slide to get earlier data, but has to move the right slicer to get the most recent data. I want to avoid that.
I do not want to filter the visual because there is historical data I want the user to be able to see, I just want the default view to be the last 30 days.
Is this at all possible?
One idea is to use a Calculation Group with a Calculation Item that applies the default Date filter to all measures if no filter has been applied. This would work fine as long as applying a date filter to measures results in all visuals displaying as intended.
(This is a similar idea to this article on SQLBI).
I have attached an example PBIX to illustrate the idea.
1. Create a measure Date Filter Message
Returns an empty string but will be modified by Calculation Item below.
Date Filter Message =
""
2. Create a Calculation Group called Date Filter
-----------------------------------
-- Calculation Group: 'Date Filter'
-----------------------------------
CALCULATIONGROUP 'Date Filter'[Filter Option]
CALCULATIONITEM "Default" = SELECTEDMEASURE ()
CALCULATIONITEM "Last 30 Days if no filter" =
VAR DateFormat = "d-mmm-yy"
VAR NumDays = 30
RETURN
IF (
CALCULATE ( ISFILTERED ( 'Date' ), ALLSELECTED ( ) ),
SELECTEDMEASURE ( ),
VAR TodayDate = TODAY ( )
VAR DateFilterMax = TodayDate - 1 -- start from TODAY - 1
VAR DateFilterMin = TodayDate - NumDays -- 30 days backwards
RETURN
IF (
ISSELECTEDMEASURE ( [Date Filter Message] ),
"Default date filter applied: " & UNICHAR ( 13 )
& FORMAT ( DateFilterMin, DateFormat )
& " — "
& FORMAT ( DateFilterMax, DateFormat ),
CALCULATE (
SELECTEDMEASURE ( ),
KEEPFILTERS (
DATESBETWEEN ( 'Date'[Date], DateFilterMin, DateFilterMax )
)
)
)
)
3. Apply a Report-level filter (or Page-level if needed): 'Date Filter'[Filter Option] = "Last 30 Days if no filter"
4. Then with no Date filter applied (via slicer or other means), the default filter is applied (with Date Filter Message displayed in a Card):
5. If a Date filter is applied, it then takes effect and overrides the default:
Would something like this work for you?
Regards
Check out the November 2023 Power BI update to learn about new features.
Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.
Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!