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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.