Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register 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! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
147 | |
85 | |
66 | |
52 | |
46 |
User | Count |
---|---|
215 | |
90 | |
83 | |
66 | |
58 |