Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Filter by value coming from another cell value (also filtered by Username) - RLS and DynamicQuery

I am new in Power BI and I faced with some issue I event don't know is possible to solve.

I have the following simple table with Persons.

a) each Person has a its own ID  [PersonId]

b) each Person has one manager identified by [ManagerId]

c) [ManagerId] coresponds to [PersonId]

 

For instance:  Anna is manager of John and Phil.

 

PersonIdUsernameFirstNameManagerId
1j@test.comJohn5
2p@test.comPhil5
3s@test.comSara6
4d@test.comDonald7
5a@test.comAnna8

 

Question: Is it possible to filter based on the username in RLS  in such a way:

- User can see data comming from "its" row and also from other user where he is assigned as a manager.

i.e: 

a) John will see only its own data (first row)

b) Anna will see her data (last row) and also John and Phil.

 

So far I did the simple RLS expression like [Username] = Username() but I don't know to handle this case.

I'm using datasource from MS SQL  in DirectQuery mode !

     

1 ACCEPTED SOLUTION
TeigeGao
Solution Sage
Solution Sage

Hi @Anonymous ,

In your scenario, we can create a table in SQL Server with CTE, this table will contains the personid and each id it can manage, then import this table to PowerBI to filter data.

Best Regards,

Teige

View solution in original post

3 REPLIES 3
TeigeGao
Solution Sage
Solution Sage

Hi @Anonymous ,

In your scenario, we can create a table in SQL Server with CTE, this table will contains the personid and each id it can manage, then import this table to PowerBI to filter data.

Best Regards,

Teige

Anonymous
Not applicable

Hi,

I managed to solve my problem thanks to @TeigeGao suggestion  - I used CTE functions and then the result was imported to Power BI (despite I rejected such a solution at the begining because of necessity to extend db ).

In additional I tried to call my CTE function for particular logged user but it seems to be not possible.

USERNAME() or USERPRINCIPALNAME() are  available in DAX expression not in Power Query where I wanted to call my sql function with "user" paramer.

Maybe someone have some hint to do this?

 

Anonymous
Not applicable

Thanks @TeigeGao  for suggestion.

But I'm still wondering if there is any possibility to do that only on Power BI sde. 

In my case the database should not be changed for this (preparing reports) purpose. Let's assumme db was prepared and is maintaining by other team and I need to use only what I have now.

Of course demontrated table was only a shortcut compared the real database 🙂 but the clue of the problem is the same.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.