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
mvyskala
Helper I
Helper I

RLS with different tables using LOOKUPVALUE and USERNAME()

Hello, I'm trying to figure out best way how to add RLS feature to my Power BI desktop report. I have few different OLAP cubes, where I can filter either name of SalesMan or name of SalesManager. I manually added table in which i convert name of SalesMan and SalesManager to our domain username. See attached tables

 

Table1: Sales

 

SalesManCategoryAmountSalesManager
SalesMan1Audio12577051,54SalesManager1
SalesMan1Cameras and camcorders215118662,79SalesManager1
SalesMan1Cell phones73948974,63SalesManager1
SalesMan1Computers264928505,00SalesManager1
SalesMan1Music, Movies and Audio Books14402953,90SalesManager1
SalesMan1TV and Video114928807,89SalesManager1
SalesMan2Audio33571565,13SalesManager1
SalesMan2Cameras and camcorders513495945,21SalesManager1
SalesMan2Cell phones181300198,38SalesManager1
SalesMan2Computers638800620,55SalesManager1
SalesMan2Music, Movies and Audio Books32744091,28SalesManager1
SalesMan2TV and Video286158689,34SalesManager1
SalesMan3Audio20928013,43SalesManager2
SalesMan3Cameras and camcorders338052950,15SalesManager2
SalesMan3Cell phones117393301,42SalesManager2
SalesMan3Computers423682371,99SalesManager2
SalesMan3Music, Movies and Audio Books21644305,33SalesManager2
SalesMan3TV and Video182847758,53SalesManager2
SalesMan4Audio84537734,21SalesManager2
SalesMan4Cameras and camcorders1495356215,91SalesManager2
SalesMan4Cell phones519590789,87SalesManager2
SalesMan4Computers1882015643,88SalesManager2
SalesMan4Music, Movies and Audio Books97013355,46SalesManager2
SalesMan4TV and Video776185859,00SalesManager2

 

 

Table2: Users

 

UserLogin
SalesMan1COMPANY\peter
SalesMan2COMPANY\thomas
SalesMan3COMPANY\eve
SalesMan4COMPANY\john
SalesManager1COMPANY\diane
SalesManager2COMPANY\francis

 

I was trying to add RLS role in this format:

[SalesMan] = "LOOKUPVALUE(Users[User],Users[Login],Username())"

 

but it seems it doesn't work.

 

The target is to add RLS feature so SalesMan can only see his results, and SalesManager will see his results and results of his subject SalesMen.

 

I'm quite new to this so I'm probably making some basic mistakes.

 

Thanks for any help

Regards


MV

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @mvyskala,

 

You can use below formula to achieve your requirement.

 

RLS Formula:

if(
ISERROR(SEARCH("SalesManager", [Role]))=FALSE(),
[SalesManager]=LOOKUPVALUE(Sheet2[User],Sheet2[Login],USERNAME())
,
[SalesMan]=LOOKUPVALUE(Sheet2[User],Sheet2[Login],USERNAME())
)

 

Comment:

Role=LOOKUPVALUE(Sheet2[User],Sheet2[Login],USERNAME())// check the role of current domain

IsManager= if(ISERROR(SEARCH("SalesManager", [Role]))=FALSE(),TRUE(),FALSE()) // check if your role is sales manager

 

Result:

 

Capture4.png

 

Notice: USERNAME function has the different result at desktop side and service side, you should deal with this issue.

Service:

Capture.PNG

Desktop:

Capture2.PNG

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @mvyskala,

 

You can use below formula to achieve your requirement.

 

RLS Formula:

if(
ISERROR(SEARCH("SalesManager", [Role]))=FALSE(),
[SalesManager]=LOOKUPVALUE(Sheet2[User],Sheet2[Login],USERNAME())
,
[SalesMan]=LOOKUPVALUE(Sheet2[User],Sheet2[Login],USERNAME())
)

 

Comment:

Role=LOOKUPVALUE(Sheet2[User],Sheet2[Login],USERNAME())// check the role of current domain

IsManager= if(ISERROR(SEARCH("SalesManager", [Role]))=FALSE(),TRUE(),FALSE()) // check if your role is sales manager

 

Result:

 

Capture4.png

 

Notice: USERNAME function has the different result at desktop side and service side, you should deal with this issue.

Service:

Capture.PNG

Desktop:

Capture2.PNG

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

@mvyskala, Thanks for your answers, your fonction works with userprincipalname?

@v-shex-msft  Are the formulas below "Comment:" measures that are being used to evaluate in the Table filter DAX expression?

Thanks a lot, I tried workaround to have different tables for SalesMan and SalesManager, but this looks better. Also my original formula had double apostrophe ("") which was wrong.
MV

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.