March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi All,
In my dashboard which is secured using RLS i have a Name Filter which can have different set of names for every user. i want power BI to select very first name (alphabetically) everytime user opens the dashboard.
Is this even possible? i checked posts but everything related to dynamic slicers are based on measures or dates.
Solved! Go to Solution.
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.
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.
Yes, it is possible to set a default selection in a Power BI slicer based on the first name alphabetically for each user. However, this requires a bit of a workaround since Power BI does not natively support dynamic default slicer selections based on row-level security (RLS).
Here’s a step-by-step approach to achieve this:
Create a Calculated Column for Alphabetical Order:
NameRank = RANKX(ALL('YourTable'[Name]), 'YourTable'[Name], , ASC, DENSE)
Create a Measure to Get the First Name:
FirstName =
CALCULATE(
FIRSTNONBLANK('YourTable'[Name], 1),
FILTER(
'YourTable',
'YourTable'[NameRank] = 1
)
)
Create a Visual Level Filter:
Set the Default Selection:
Implement Row-Level Security (RLS):
Here’s a more detailed example:
Calculated Column:
NameRank = RANKX(ALL('YourTable'[Name]), 'YourTable'[Name], , ASC, DENSE)
Measure:
FirstName =
CALCULATE(
FIRSTNONBLANK('YourTable'[Name], 1),
FILTER(
'YourTable',
'YourTable'[NameRank] = 1
)
)
Visual Level Filter:
FirstName measure as a filter to the slicer visual.
Bookmarks and Buttons:
This approach ensures that each user sees the first name alphabetically in the slicer based on their RLS context, and they can reset the slicer to this default state using a button.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
123 | |
82 | |
69 | |
53 | |
44 |
User | Count |
---|---|
202 | |
106 | |
100 | |
64 | |
56 |