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
Anonymous
Not applicable

Default value set in Slicer

Hi,

 

 I need to set default current year "2020" set in one slicer and second slicer to set default current month "july" and also so other year show in slicer pane. so how to possible in Power BI .see the attached file.

 

 

Month.PNGyear.PNG

 

Thanks in Advance

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

@Anonymous ,

 

Slicer doesn't support setting default selection, you could refer to my workaround using M code below:

let
    Source = List.Dates(#date(2019, 1, 1), 731, #duration(1, 0, 0, 0)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Calendar"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "CurrentMonth", each Date.Month(DateTime.LocalNow())),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "CurrentYear", each Date.Year(DateTime.LocalNow())),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "IsCurrentYear", each if Date.Year([Calendar]) = [CurrentYear] then "CurrentYear" else Date.Year([Calendar])),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "IsCurrentMonth", each if Date.Month([Calendar]) = [CurrentMonth] then "CurrentMonth" else Date.Month([Calendar]))
in
    #"Added Custom3"

 

Then create two slicers based on [IsCurrentYear] and [IsCurrentMonth] as below:

Capture.PNG 

Regards,

Jimmy Tao

View solution in original post

1 REPLY 1
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

Slicer doesn't support setting default selection, you could refer to my workaround using M code below:

let
    Source = List.Dates(#date(2019, 1, 1), 731, #duration(1, 0, 0, 0)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Calendar"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "CurrentMonth", each Date.Month(DateTime.LocalNow())),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "CurrentYear", each Date.Year(DateTime.LocalNow())),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "IsCurrentYear", each if Date.Year([Calendar]) = [CurrentYear] then "CurrentYear" else Date.Year([Calendar])),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "IsCurrentMonth", each if Date.Month([Calendar]) = [CurrentMonth] then "CurrentMonth" else Date.Month([Calendar]))
in
    #"Added Custom3"

 

Then create two slicers based on [IsCurrentYear] and [IsCurrentMonth] as below:

Capture.PNG 

Regards,

Jimmy Tao

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.