Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
As you might know Power BI offers a very nice role management that allows filtering the data based on role(s) associated with the user.
A basic use of this feature is presented in https://powerbi.microsoft.com/en-us/documentation/powerbi-admin-rls/.
A more dynamic use of this feature is very well explained in http://radacad.com/dynamic-row-level-security-with-power-bi-made-simple .
But this latest option still requires to maintain a table of some sort where we associate users and their roles.
Most organizations already have associated roles to users in Active Directory and this posts aims at demonstrating how to leverage this.
It explains:
How to connect to AD
This is easy because Active Directory is one the listed Data Sources
How to select the data we need in AD
After connecting to your domain, you will be presented with dozens of table. Only one of those is interesting for use here: User
How to transform the data in a way that makes it usable in PBI
What we need for every user is their email address (because it’s the user ID in PBI) and the groups they are associated with.
Expand the user column and look only for “mail”
Groups are in the distinguishedName column but it requires a bit of work to be usable
First split the column on the “,” delimiter
Then select all the distinguishedName.* columns and unnpivot them
Then split the new “Value” column on the “=” sign
If you wish you can then rename the colums. I think those are called nodes in AD so I called them
NodeID, NodeType and NodeName.
NB: if, like me, you wondered what CN, OU, DC stand for, here it is
Tadam you are all set!
For any user you can get the group (Nodes) they belong to
And more important you can get all the users that belong to a given group
How to leverage the data in PBI
Now you are simply back to the role creation issue, where you can filter the data based on the group (NodeName) of the user.
To illustrate this let’s take this financial sample workbook: http://go.microsoft.com/fwlink/?LinkID=521962
Let’s say people from the GPO group should only see data from Canada.
We need to create a table that stores all those associations.
So sure we still have a table to maintain, but this is still much more dynamic because we don’t have to maintain the group/user association. Everytime a user joins or leave a group in AD, the data get filtered accordingly.
Now we need to link this table to both the user table on the group and to the data table on the country
The last piece is the association of the current user to the user.mail at run time. This is achieved by creating a role
In the user table add the following table filter DAX expression:
[user.mail] = username()
The last step is to get the role to be applied at run time by applying the role to all users.
Once you application has been published in the cloud open the security menu of the dataset.
And add the role to all users.
The application of the role at runtime will cause
----------------
APPENDIX
In real life you will probably have several countries visible for a given group and several groups accessing the same countries.
In other words you will end-up with many-to-many relationships that you will need to tackle by creating relationship tables.
You can easily create those tables by referencing the existing tables
Keeping only the column you are interested in, in our case the NodeName column
Then the final step is to remove duplicates
For the relationship to work you might need to make sure there is no empty row in the list.
Please note that Power Query and PowerBI currently don’t have the same definition of duplicates (https://community.powerbi.com/t5/Desktop/Power-Query-and-PowerBI-currently-don-t-have-the-same-defin...) so be careful
You can now do the same to get a list of all unique countries
Which will lead you to this new data model
But for the relationships to work as expected you will need to edit the relationships
And set the Cross fitler direction to Both
That's a very interesting topic! My solution doesn't want to work though:
in the user table I have e.g. email examplename@cortoso.com with the country and in the role I say email = username()
When I run the view as other user "examplename@cortoso.com" it doesn't filter the country.
User n:1 Country 1:n Facts Table
Should that work?
Thanks, BR Roman
Hi,
Thanks for the article, but I have few doubts.
Why should I add users to the roles/groups tab individually? I should be able to put the name of the group directly so that I save the hassle of adding the AD group members one-by-one.
Can you please help
Hi @GilbertQ ,
I have that mapping for user to group to check that. But where I am getting stuck is when I am trying to get the AD group name populated in the service, they are not showing up.
The only column that's missing from my data is the group mail id. Is it the reason that I am not able to see the group names?
Thank you so much for this guide. However, I am still really new to Active Directory (like 1 day old) and I am still learning it. I was wondering, how do you establish dynamic row level security for the groups from here?
Hi there,
Love the idea of using the AD for permissions. I have a question though.
If a user changes group or region for an example. How easy would it be to update this solution to reflect that change and show the user the right data. Would the process have to be done all over since AD isn't a source that has data refresh.
Cheers. 🙂
Hi @osinquinvdm,
Thanks for your sharing.
Thanks,
Lydia Zhang
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
85 | |
74 | |
68 | |
51 | |
30 |
User | Count |
---|---|
115 | |
109 | |
71 | |
65 | |
39 |