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
swise001
Continued Contributor
Continued Contributor

Row Level Security - Explain why this DAX using Lookupvalue works for multiple results

I'm using an overly simple data model where UserTablewithRegion is disconnected (ignore the Users and User_Region tables). 

 

swise001_0-1599048292539.png

Im using this DAX for a dynamic role; 

swise001_1-1599048364537.png

This absolutely works for this model and will work even when multiple different "Teams" are returned for a single users.  

 

Curiously - this same DAX when enetered in Power BI - as a measure - does not work. 

swise001_2-1599048506974.png

 

Can someone explain why this DAX works for multiple results when used in an RLS role?

 

("Team" and "RegionID" are simple letters "A","B","C", )

Thank you!

 

1 ACCEPTED SOLUTION
swise001
Continued Contributor
Continued Contributor

Solved

 

The additional fields included as part of the lookupvalue() dax rule  are like an "AND" condition on the lookup itself. 

Consider the original formula: 

 

[RegionID] =
LOOKUPVALUE (
                UserTablewithRegion[Team],
                UserTablewithRegion[Email], USERPRINCIPALNAME(),

                UserTablewithRegion[Team],Regions[RegionID]
)

 

and let's rewrite it with context: 

 

Return the Team from the UserTablewithRegion Table 

WHERE

UserTablewithRegion[Email] = USERPRINCIPALNAME()

AND

UserTablewithRegion[Team] = Region[RegionID]

 

It would be possible to add more search terms as well.  If I remove this second condition - the lookupvalue no longer returns one result so it fails.  By including the Team=RegionID at the end - the formula is now able to have 1 result per combination:

 

 

View solution in original post

6 REPLIES 6
swise001
Continued Contributor
Continued Contributor

Solved

 

The additional fields included as part of the lookupvalue() dax rule  are like an "AND" condition on the lookup itself. 

Consider the original formula: 

 

[RegionID] =
LOOKUPVALUE (
                UserTablewithRegion[Team],
                UserTablewithRegion[Email], USERPRINCIPALNAME(),

                UserTablewithRegion[Team],Regions[RegionID]
)

 

and let's rewrite it with context: 

 

Return the Team from the UserTablewithRegion Table 

WHERE

UserTablewithRegion[Email] = USERPRINCIPALNAME()

AND

UserTablewithRegion[Team] = Region[RegionID]

 

It would be possible to add more search terms as well.  If I remove this second condition - the lookupvalue no longer returns one result so it fails.  By including the Team=RegionID at the end - the formula is now able to have 1 result per combination:

 

 

amitchandak
Super User
Super User

@swise001 , In case you creating a column, this should work. If you are creating a measure you need to use some aggregation or functions like sumx, countx etc

swise001
Continued Contributor
Continued Contributor

@amitchandak 

The DAX is for creating a rule in my Row Level Security Role.  This is at the heart of my question.  

Greg_Deckler
Super User
Super User

@swise001 - Row context versus no row context. Measures do not have row context and thus you must use an aggregator like SUM, MAX, MIN, AVERAGE, etc. when referencing columns.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

I'm not sure if I'm satisfied with that response. 

If I remove the last two fields from the measure - it no longer works. 

swise001_0-1599049412933.png

swise001_1-1599049438882.png

 

Can you better explain why these two values at the end of the DAX used in the measure are the difference between it working and not working?  Does DAX used in RLS run like a calculated column? 

 

@swise001 - Yes, it is like a calculated column, hence it has row context. Think of it this way, you create a calculated column that returns true or false as to whether you can see it or not. RLS is kind of it's own thing and I have no idea how they are translating the DAX you input into the actual security, it's kind of black box that way. But, the fact that you can reference columns without aggregation demonstrates that however they are implementing it, it respects row context, which kind of makes sense since it is "row" level security after all.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.