Forum Discussion

kgandhi2001's avatar
kgandhi2001
Frequent Visitor
3 years ago
Solved

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?

 

 

 

Thank You in advance

 

Regards,

gk03

  • 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":

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

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

    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.

    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

5 Replies

  • kgandhi2001's avatar
    kgandhi2001
    Frequent Visitor

    Hello DimaMD

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

     

  • kgandhi2001's avatar
    kgandhi2001
    Frequent Visitor

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

  • 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":

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

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

    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.

    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

    • doom_dadd's avatar
      doom_dadd
      New Member

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