cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
pbi_throw_away
Frequent Visitor

On report load, slicer to default to last 30 days including yesterday, not including today

slicer.png

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?

1 REPLY 1
OwenAuger
Super User
Super User

Hi @pbi_throw_away 

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):

OwenAuger_2-1694267819373.png

 

5. If a Date filter is applied, it then takes effect and overrides the default:

 

OwenAuger_3-1694267840632.png

 

Would something like this work for you?

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

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!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors