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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Sunshine123
Frequent Visitor

How to set default on data slicer when open Power BI

Hi, 

I want to create a default on a slicer to the current week, when open Power BI. So it must be dynamic. 

Any suggestions?

Sunshine123_0-1646833097474.png

Many Thanks!

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

Hi @Sunshine123 ,

 

I'd like to suggest you to create a slicer table like below.

slicer = 
var _table = SELECTCOLUMNS(CALENDAR(DATE(2020,1,1),DATE(2022,12,31)),"week",YEAR([Date])&"_"&WEEKNUM([Date]))
var _thisweek = SELECTCOLUMNS(_table,"week","this_week")
return
distinct(UNION(_table,_thisweek))

1.jpg

Then create a measure like below:

measure =
VAR _weeknum =
SELECTEDVALUE ( 'table'[week] )
RETURN
IF (
SELECTEDVALUE ( 'slicer'[week] ) = "this_week",
IF ( _weeknum = WEEKNUM ( TODAY () ), 1, 0 ),
IF ( _weeknum = SELECTEDVALUE ( 'slicer'[week] ), 1, 0 )
)

Add this measure to visual filter set value = 1.

The visual will display value of the latest week when "this week" is selected.

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

3 REPLIES 3
v-jayw-msft
Community Support
Community Support

Hi @Sunshine123 ,

 

I'd like to suggest you to create a slicer table like below.

slicer = 
var _table = SELECTCOLUMNS(CALENDAR(DATE(2020,1,1),DATE(2022,12,31)),"week",YEAR([Date])&"_"&WEEKNUM([Date]))
var _thisweek = SELECTCOLUMNS(_table,"week","this_week")
return
distinct(UNION(_table,_thisweek))

1.jpg

Then create a measure like below:

measure =
VAR _weeknum =
SELECTEDVALUE ( 'table'[week] )
RETURN
IF (
SELECTEDVALUE ( 'slicer'[week] ) = "this_week",
IF ( _weeknum = WEEKNUM ( TODAY () ), 1, 0 ),
IF ( _weeknum = SELECTEDVALUE ( 'slicer'[week] ), 1, 0 )
)

Add this measure to visual filter set value = 1.

The visual will display value of the latest week when "this week" is selected.

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
amitchandak
Super User
Super User

@Sunshine123 , You have to use workaround. We do not have function support yet

 

have a column like this in table

 

Week Type =
var _st = today() +-1*WEEKDAY(today() ,2)+1
var _end = today() + 7-1*WEEKDAY(today(),2)
return
Switch( True(),
[Date] >= _st && [Date] <= _end ,"This Week" ,
[Date] >= _st-7 && [Date] <= _end -7,"Last Week" ,
[Week Name]
)

 

then save on this week

Thanks @amitchandak! It worked very well. 

How can set a default on "This Week" on the slicer now? Each time when a user will open the file I want "This Week"preselected. 

Many thanks in advance! 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.