Forum Discussion
Complexity RLS - Help please!
- 9 months ago
Hi PedroModa,
For Sure, Here is Simple and clear solution Step by Step you can Do :
First Step is to Create Security Table called UserSecurity with all user permissions like this:UserEmail CostCenter RestrictedSupplier [email protected] 1-1.000010 [email protected] 2-1.000012 [email protected] 1-1.000010 0009789 Until you reach end (25) etc Second Step is to put RLS Rules for Each Table
- dCentrodeCusto (dimension):
[COLI-CODCUSTO] IN VALUES(UserSecurity[CostCenter])- dFornecedor (dimension):
NOT([CODCFO] IN VALUES(UserSecurity[RestrictedSupplier]))- dMedContratos (hide entire table):
[Contrato] IN {""} // Or use FALSE() to hide everything- fAjusteGerencial (fact table):
VAR TI = RELATED(dCentrodeCusto[NOME]) = "TECNOLOGIA DA INFORMACAO" VAR ValidAccount = NOT([Conta] IN { "Salários E Ordenados", "Hora Extra", "Encargos Trabalhistas", "Rescisões E Indenizações", "Prêmios E Bonificações" }) RETURN TI && ValidAccount- fBalancete (fact table):
VAR TI = RELATED(dCentrodeCusto[NOME]) = "INFORMATION TECHNOLOGY" VAR ValidAccount = NOT(RELATED('dC Account'[Management Accounts]) IN { "Salaries and Wages", "Overtime", "Labor Charges", "Terminations and Compensation", "Bonuses and Bonuses" }) VAR InitialExpense = NOT([COMPLEMENT2] = "JOAO DA SILVA") RETURN TI && ValidAccount && InitialExpense- fPartida and fpitempartida (hide everything):
FALSE() // Hides all rows- ftmovitens and fvalorcado (Use same logic as fAjusteGerencial but adapt column names)
Third and Last Step is to add this to UserSecurity table:
[UserEmail] = USERPRINCIPALNAME()I hope you find this useful cause it took too much time and if you need any help tell me and sorry for delay reply 🫡❤️
Thank you very much! I've seen some content about dynamic RLS, but since I've never worked with it before, I still have many questions... One of them is, for example, if this manager can view 25 cost centers, should I create 25 rows in the table for this manager? For example:
[email protected] | cost center 1
[email protected] | cost center 2
[email protected] | cost center 3
And so on?
And in cases where, for example, I wanted to "hide" the information in a column of ONE TABLE for this rule:
[email protected] | cost center 2
the transactions table, for example, I want to hide the information for supplier 3...
How would I do that? This is very confusing for me. Should I handle this in the table itself, or should I do this more "detailed" handling within Power BI?
Hi PedroModa,
So lets Take questions one by one 😅❤️
First Question
If this manager can view 25 cost centers should you create 25 rows in the table for this manager?
- So Yes Exactly create 25 separate rows exactly like this:
| UserPrincipalName | CostCenter |
| [email protected] | CC01 |
| [email protected] | CC02 |
| [email protected] | CC03 |
| [email protected] | until reach the max (25) |
Second Question
What's the RLS rule for this structure?
- Just a single and simple rule on your security table:
[UserPrincipalName] = USERPRINCIPALNAME()
Third Question
How do I hide a supplier in only ONE table?
- So For this Question there is 2 Approaches you could try (the more comfortable for you)\
- First one is to add restriction columns to your main security table:
| UserPrincipalName | CostCenter | RestrictedSupplier |
| [email protected] | CC02 | Supplier3 |
And the RLS Rule for this:
AND(
[CostCenter] IN VALUES(SecurityTable[CostCenter]),
NOT([Supplier] IN VALUES(SecurityTable[RestrictedSupplier]))
)- Second one is to create dedicated tables for different restriction types:
| UserPrincipalName | RestrictedSupplier |
| [email protected] | Supplier3 |
And the RLS Rule for this Table is:
// Main cost center access
[CostCenter] IN VALUES(UserCostCenterAccess[CostCenter])
// Supplier restrictions
NOT([Supplier] IN VALUES(UserSupplierRestrictions[RestrictedSupplier]))
Finally
You should always handle this in the RLS tables (not inside Power BI visuals or complex DAX)
Power BI RLS is relationship driven (not DAX driven) , So each restriction type must have its own small table