Forum Discussion
DAX Code for Dynamic RLS
- 6 years ago
sorry, was a bit quick there, you need to write it like this
VAR _t = CALCULATETABLE ( VALUES ( 'Access_Table'[Access_Required] ), FILTER ( 'Access_Table', 'Access_Table'[User_Email] = USERPRINCIPALNAME () ) ) RETURN IF ( CONTAINS ( _t, 'Access Table'[Access_Required], "National" ) || CONTAINS ( _t, 'Access Table'[Access_Required], "Regional" ), 'dimCompany'[Company] IN CALCULATETABLE ( VALUES ( 'Access_Table'[Company] ), FILTER ( 'Access_Table', 'Access_Table'[User_Email] = USERPRINCIPALNAME () ) ), TRUE () )
Firstly, thank you so much you've been really helpful!
I am 99% of the way there however I am having issues with the 'Regional' filter. Where currently if you are under the regional filter you can see your region e.g. USA but for all companies and can filter through other companies, instead of being able to only view your companies region.
Sorry, you lost me. You want to see region but not all companies in that region? And only see your own company?
Could you create a mockup to show your desired outcome?
- Anonymous6 years agoNot applicable
So each company could have a number of regions under it for example:
Company Region Apple UK Apple USA Apple CAN Microsoft UK Microsoft USA Microsoft CAN When a user is set up as 'Regional' it means that they should only see records that are in their region AND in their company as this will be shared externally. Does that make sense?
sturlaws wrote:Sorry, you lost me. You want to see region but not all companies in that region? And only see your own company?
Could you create a mockup to show your desired outcome?
- sturlaws6 years agoResident Rockstar
Now that would have been pertinent information to include in your sample data file ;)
In the filter expression of dimCompany change this
'Access Table'[Access_Required], "National"
to
'Access Table'[Access_Required], "National" || 'Access Table'[Access_Required], "Regional"
And for dimRegion, change
'Access Table'[Access_Required], "Regional"
to
'Access Table'[Access_Required], "National"
- Anonymous6 years agoNot applicable
My apologies for missing that bit of key info out!
When trying to change the DAX its throwing the error 'The number of arguments is invalid. Function CONTAINS must have a value for each specified column reference.?