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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
kgandhi2001
Frequent Visitor

How to set default values dynamically for slicer?

Hello -

 

How to set default values dynamically for the slicer? E.g. At any moment we want to set only most recent 5 days to the below screenshot slicer visual. So if today is 01/10/2023 then from should be 01/06/2023 and to should be 01/10/2023.

 

Any help how to set it?

 

kgandhi2001_0-1673333535461.png

 

 

Thank You in advance

 

Regards,

gk03

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @kgandhi2001 

According to your description, you want to "set default values dynamically for slicer".

Here are teh steps you can refer to :
(1)For the slicer that comes with Power BI, we can not get it. But we can get the three point in the "Visualizations", and we click the "Get more visual":

vyueyunzhmsft_0-1673408398107.jpeg

Then we find the "Preselected Slicer" and add the visual to our Power Bi Desktop.

vyueyunzhmsft_1-1673408409850.jpeg

First , we need to create a table with one column , and the value is True and False, like this:

vyueyunzhmsft_2-1673408428483.png

Second , we can create a measure to define which the date we need to default preselected. If we need to default preselect then we return True else return False.

Flag = var _date =SELECTEDVALUE('Date'[Date])
var _today = TODAY()
var _last_5_days = _today -4
return
IF(_date>= _last_5_days , TRUE(),FALSE())

 Then we can default dynamic preslect the last three months in the slicer visual , and when we select other date, we just need to click the red reset button in the upper right corner to recover the defalt selections.

vyueyunzhmsft_3-1673408463856.png

You can also refer to this:
Solved: How to set last 2 months as default filter in a po... - Microsoft Power BI Community

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

5 REPLIES 5
v-yueyunzh-msft
Community Support
Community Support

Hi , @kgandhi2001 

According to your description, you want to "set default values dynamically for slicer".

Here are teh steps you can refer to :
(1)For the slicer that comes with Power BI, we can not get it. But we can get the three point in the "Visualizations", and we click the "Get more visual":

vyueyunzhmsft_0-1673408398107.jpeg

Then we find the "Preselected Slicer" and add the visual to our Power Bi Desktop.

vyueyunzhmsft_1-1673408409850.jpeg

First , we need to create a table with one column , and the value is True and False, like this:

vyueyunzhmsft_2-1673408428483.png

Second , we can create a measure to define which the date we need to default preselected. If we need to default preselect then we return True else return False.

Flag = var _date =SELECTEDVALUE('Date'[Date])
var _today = TODAY()
var _last_5_days = _today -4
return
IF(_date>= _last_5_days , TRUE(),FALSE())

 Then we can default dynamic preslect the last three months in the slicer visual , and when we select other date, we just need to click the red reset button in the upper right corner to recover the defalt selections.

vyueyunzhmsft_3-1673408463856.png

You can also refer to this:
Solved: How to set last 2 months as default filter in a po... - Microsoft Power BI Community

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

this solution is good but it seems that doesn't support dynamic M query parameters

kgandhi2001
Frequent Visitor

@DimaMD - Can you please share your DAX function? What should be for [measure]? I posted screenshot in my previous response.

kgandhi2001
Frequent Visitor

Hello DimaMD

I was not following your DAX logic. it is throwing an error

kgandhi2001_0-1673362548751.png

 

DimaMD
Solution Sage
Solution Sage

@kgandhi2001  hi try it

CALCULATE(
         [measure],
            DATEADD('dates'[Date],
                -5,
                DAY)
            )

__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.