Forum Discussion

PedroModa's avatar
PedroModa
Helper I
8 months ago
Solved

Complexity RLS - Help please!

Hi everyone, good evening! I need some help.   Recently, a user reached out saying he couldn’t use one of our Power BI reports. At first, I found it strange because he was the only one reporting is...
  • Ahmed-Elfeel's avatar
    Ahmed-Elfeel
    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:

     

    UserEmailCostCenterRestrictedSupplier
    [email protected]1-1.000010 
    [email protected]2-1.000012 
    [email protected]1-1.0000100009789
    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 🫡❤️