Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
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.
Thanks in Advance
Solved! Go to Solution.
@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:
Regards,
Jimmy Tao
@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:
Regards,
Jimmy Tao
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
94 | |
84 | |
84 | |
73 | |
49 |
User | Count |
---|---|
143 | |
132 | |
110 | |
64 | |
55 |