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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It 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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors