Forum Discussion
Dynamic Slicer for selecting alphabetically first name by default
- Anonymous1 year ago
Hi,MAwwad ,thanks for your concern about this issue.
Your answer is excellent!
And I would like to share some additional solutions below.Hello,sups7302 .I am glad to help you.
I created a simple example that I hope will give you some good ideas.
Here is my test data.You need to create a sort sequence for the fields used by the slicer you want to sort and set the sort for them.
configure RLSView AS RLS_Role
The RLS was successfully set and the slicer fields were successfully sorted (alphabetically) according to the set sorting sequence.
Sort by alphabetical order
This is my test code, hope it helps.
You need to write your own sorting logic (based on which fields are sorted according to what judgment logic, etc.), create a correct sorting sequence, and make sure that the RLS is set up correctly, and that the Role is assigned correctly after uploading it to the Power BI Service.
M code:let Source = Sql.Database("vm0", "AdventureWorksDW2022"), dbo_RLSGroup = Source{[Schema="dbo",Item="RLSGroup"]}[Data], // The following steps create the sorting sequence to ensure that the slicers are in the correct order, you need to write your own sorting logic based on the actual sorting situation. // Group by GroupID GroupedRows = Table.Group(dbo_RLSGroup, {"GroupID"}, {{"GroupedData", each _, type table [UserID=Int64.Type, NickNames=Text.Type, GroupID=Int64.Type, ProjectNames=Text.Type]}}), // Sort by NickNames within each group and add index columns AddIndex = Table.TransformColumns(GroupedRows, {"GroupedData", each Table.AddIndexColumn(Table.Sort(_, {{"NickNames", Order.Ascending}}), "Index", 1, 1, Int64.Type)}), #"Expanded GroupedData" = Table.ExpandTableColumn(AddIndex, "GroupedData", {"UserID", "NickNames", "ProjectNames", "UPN", "Index"}, {"GroupedData.UserID", "GroupedData.NickNames", "GroupedData.ProjectNames", "GroupedData.UPN", "GroupedData.Index"}), #"Renamed Columns" = Table.RenameColumns(#"Expanded GroupedData",{{"GroupedData.UserID", "UserID"}, {"GroupedData.NickNames", "NickNames"}, {"GroupedData.ProjectNames", "ProjectNames"}, {"GroupedData.UPN", "UPN"}, {"GroupedData.Index", "SortIndex"}}) in #"Renamed Columns"I have uploaded the corresponding pbix file, hopefully it will give you good ideas.
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,MAwwad ,thanks for your concern about this issue.
Your answer is excellent!
And I would like to share some additional solutions below.
Hello,sups7302 .I am glad to help you.
I created a simple example that I hope will give you some good ideas.
Here is my test data.
You need to create a sort sequence for the fields used by the slicer you want to sort and set the sort for them.
configure RLS
View AS RLS_Role
The RLS was successfully set and the slicer fields were successfully sorted (alphabetically) according to the set sorting sequence.
Sort by alphabetical order
This is my test code, hope it helps.
You need to write your own sorting logic (based on which fields are sorted according to what judgment logic, etc.), create a correct sorting sequence, and make sure that the RLS is set up correctly, and that the Role is assigned correctly after uploading it to the Power BI Service.
M code:
let
Source = Sql.Database("vm0", "AdventureWorksDW2022"),
dbo_RLSGroup = Source{[Schema="dbo",Item="RLSGroup"]}[Data],
// The following steps create the sorting sequence to ensure that the slicers are in the correct order, you need to write your own sorting logic based on the actual sorting situation.
// Group by GroupID
GroupedRows = Table.Group(dbo_RLSGroup, {"GroupID"}, {{"GroupedData", each _, type table [UserID=Int64.Type, NickNames=Text.Type, GroupID=Int64.Type, ProjectNames=Text.Type]}}),
// Sort by NickNames within each group and add index columns
AddIndex = Table.TransformColumns(GroupedRows, {"GroupedData", each Table.AddIndexColumn(Table.Sort(_, {{"NickNames", Order.Ascending}}), "Index", 1, 1, Int64.Type)}),
#"Expanded GroupedData" = Table.ExpandTableColumn(AddIndex, "GroupedData", {"UserID", "NickNames", "ProjectNames", "UPN", "Index"}, {"GroupedData.UserID", "GroupedData.NickNames", "GroupedData.ProjectNames", "GroupedData.UPN", "GroupedData.Index"}),
#"Renamed Columns" = Table.RenameColumns(#"Expanded GroupedData",{{"GroupedData.UserID", "UserID"}, {"GroupedData.NickNames", "NickNames"}, {"GroupedData.ProjectNames", "ProjectNames"}, {"GroupedData.UPN", "UPN"}, {"GroupedData.Index", "SortIndex"}})
in
#"Renamed Columns"
I have uploaded the corresponding pbix file, hopefully it will give you good ideas.
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.