Forum Discussion
Complexity RLS - Help please!
- 8 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 🫡❤️
Hi PedroModa,
I hope you are doing well today ☺️❤️
So the issue is likely the additive nature of RLS when a user is assigned to multiple roles; your user's membership in 25 roles means Power BI must combine the filters from all of them which can severely impact performance (The OR conditions within each rule further complicate the filtering logic)
So what should you do to solvethis issue?...Here is some approach you can try :
First Approach : (Long term scalability and for large organizations)
Create a central table linking users to their cost centers (this can be an Excel sheet,database table or SharePoint list that you import)
Use one RLS role with:
[Username] = USERNAME()- Relate this table to your data model (filters propagate automatically)
Second Approach (Quick fix)
Merge 25 roles into 1-3 broader roles
- Replace multiple OR conditions with single IN clause
- Reduce additive filtering overhead
Third Approach
- Combine RLS with page-level filters
- Use summary tables for managerial views
- Implement RLS sparingly
Final Approach (Technical Optimize)
- Convert text codes to integer IDs
Ensure single direction relationships
- Use imported tables vs direct query