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
Jigyasa_11
Frequent Visitor

Default Date value on the slicer to be of past month

Hi, I want to set default date for my from date and to date slicer. If I open the dashboard today it should show me default date of past month. Like if I open today (4 April) then the From date should be 1 March and To date should be 31 march in the slicer.

or if thats not possible then how to show sysdate - 30 dates in the slicer, like if I open today (4 april) then I should be able to see from date 4 march and to date 4 april. 

Jigyasa_11_0-1712556347708.png

I am using May 2023 Power BI Desktop version.

 

All suggestions are welcomed, thank you! 

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

Hi  @Jigyasa_11 ,

You might consider using "Preselected Slicer".

For the slicer that comes with Power BI, we cannot get it. But we can get the three point in the "Visualizations", and we click the "Get more visual":

vyangliumsft_0-1713770478748.png

Here are the steps you can follow:

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

vyangliumsft_1-1713770478749.jpeg

2. Create a table – Slicer table.

Table 2 =
DISTINCT('Table'[Date])

vyangliumsft_2-1713770497571.png

3. 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 _today=TODAY()
var _mindate=
EOMONTH(_today,-2)
var _maxdate=
EOMONTH(_today,-1)
return
IF(
    MAX('Table 2'[Date])>_mindate&&MAX('Table 2'[Date])<=_maxdate,TRUE(),FALSE())

vyangliumsft_3-1713770497575.png

4. Create a measure to be placed in Visual's filter and set it to 1 to display the date according to our customized rules.

Flag_Test =
var _count=COUNTX(ALLSELECTED('Table 2'),[Date])
var _mindate=MINX(ALLSELECTED('Table 2'),[Date])
var _maxdate=MAXX(ALLSELECTED('Table 2'),[Date])
return
SWITCH(
    TRUE(),
    _count=1&&MAX('Table'[Date])=_mindate,1,
    _count>=2&&MAX('Table'[Date])>=_mindate&&MAX('Table'[Date])<=_maxdate,1,0)

vyangliumsft_4-1713770542755.png

5. Result.

The default state shows the previous month's value

vyangliumsft_5-1713770542761.png

If you want to display individual values, you can just click on the individual dates:

vyangliumsft_6-1713770572217.png

Select two dates to show all dates between them.

vyangliumsft_7-1713770572219.png

Note: If you want to go back to the default state, click on the red circle in the upper right corner of the slicer above.

 

Best Regards,

Liu Yang

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-yangliu-msft
Community Support
Community Support

Hi  @Jigyasa_11 ,

You might consider using "Preselected Slicer".

For the slicer that comes with Power BI, we cannot get it. But we can get the three point in the "Visualizations", and we click the "Get more visual":

vyangliumsft_0-1713770478748.png

Here are the steps you can follow:

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

vyangliumsft_1-1713770478749.jpeg

2. Create a table – Slicer table.

Table 2 =
DISTINCT('Table'[Date])

vyangliumsft_2-1713770497571.png

3. 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 _today=TODAY()
var _mindate=
EOMONTH(_today,-2)
var _maxdate=
EOMONTH(_today,-1)
return
IF(
    MAX('Table 2'[Date])>_mindate&&MAX('Table 2'[Date])<=_maxdate,TRUE(),FALSE())

vyangliumsft_3-1713770497575.png

4. Create a measure to be placed in Visual's filter and set it to 1 to display the date according to our customized rules.

Flag_Test =
var _count=COUNTX(ALLSELECTED('Table 2'),[Date])
var _mindate=MINX(ALLSELECTED('Table 2'),[Date])
var _maxdate=MAXX(ALLSELECTED('Table 2'),[Date])
return
SWITCH(
    TRUE(),
    _count=1&&MAX('Table'[Date])=_mindate,1,
    _count>=2&&MAX('Table'[Date])>=_mindate&&MAX('Table'[Date])<=_maxdate,1,0)

vyangliumsft_4-1713770542755.png

5. Result.

The default state shows the previous month's value

vyangliumsft_5-1713770542761.png

If you want to display individual values, you can just click on the individual dates:

vyangliumsft_6-1713770572217.png

Select two dates to show all dates between them.

vyangliumsft_7-1713770572219.png

Note: If you want to go back to the default state, click on the red circle in the upper right corner of the slicer above.

 

Best Regards,

Liu Yang

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

v-yangliu-msft
Community Support
Community Support

Hi  @Jigyasa_11 ,

 

Thanks for the reply from @Idrissshatila , please allow me to provide another insight: 

 

Here are the steps you can follow:

1. Create measure.

Flag =
var _today=TODAY()
return
IF(
    MAX('Table'[Date]) >=DATE(YEAR(_today),MONTH(_today)-1,1)&& MAX('Table'[Date])<=EOMONTH(_today,-1),1,0)

2. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_0-1712644874213.png

3. Result:

vyangliumsft_1-1712644874214.png

 

 

Best Regards,

Liu Yang

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

Thank you for sharing this @v-yangliu-msft . Really helpful. So nice of you to share the file as well. Thanks a lot.

So what I am looking for is when user opens the dashboard then default date should be set to past 1 month dates. But after opening if the user wants then should be able to select any date to see data as per the choice of dates. Like when dashboard is opened date should be of March 1 to March 31, but then user should be able to select any date of past. Just at the time of first load of dashboard, default date should be of past 1month. With your solution I am able to default  past 1 month but then all other past/future(Current month) dates are disabled.

Idrissshatila
Super User
Super User

Hello @Jigyasa_11 ,

 

check this out https://youtu.be/pt7dI8af_m8?si=6r2hPbWkTpFz0WkH

 



Did I answer your question? Mark my post as a solution! Appreciate your Kudos
Follow me on LinkedIn linkedIn
Vote for my Community Mobile App Idea

Proud to be a Super User!




Thank you for sharing this @Idrissshatila . But this doesnt solve my problem exactly.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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