﻿//Metadata: 
//Programming language: DAX
//Natural language: English 
//Output: RowLevelSecurity setting 
 
//Explanation: 
//RowLevelSecurity can be defined by a variety of . 3 options are provided heree

//How to use: 
//Copy 1 of these codes into Power BI RLS Editor when implementing RowLevelSecurity


1. USERBASED_RLS =

    
    [EmployeeEmail] == USERPRINCIPALNAME() //This code compares the email addresses of the column and the current report viewer
    


2. ROLEBASED_RLS =
    
    VAR User = USERPRINCIPALNAME()
    
    RETURN
    [ProjectLeadEmail] == User || [ProjectSupportEmail] == User //Same scenario as 1., but with the employees email adress can be contained in 2 columns as 2 roles are possible 
    
    
    
3. COMPANYBASED_RLS =

	VAR Company =
    IF (
        CONTAINSSTRING ( USERPRINCIPALNAME (), "CompanyXYZ" ),
        "CompanyXYZ",
        "CompanyABC"
    )
    
	RETURN
    FILTER ( YourTableName, Company = "CompanyXYZ" ) //This case can be used to share Reports with people from other organizations