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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.