Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
ConnieMaldonado
Responsive Resident
Responsive Resident

Create table dynamically for use in PATH Statement

Hello - I'm trying to use a path statement on an Employee table to set up Row Level Security.

 

The employee table is updated daily and goes back 15 years. It contains active and terminated employees.
I have employee ID and Supervisor ID for each employee.  Here is mock data representing the employee table:

 

EMPLOYEE_NUMBEREMPLOYEE_NAMESUPERVISOR_EMPLOYEE_NUMBERSUPERVISOR_NAMEEMPLOYEE_TERMINATION_DATESUPERVISOR_TERMINATION_DATE
123456ABCJohn Doe555879LLLAngelina Jolie  
234567DEFJames Smith666454KLMSam Heughan  
345678GHIJorge Rodriguez659874STUTom Cruise 1/2/2019
456789JKLJulia Roberts258147PQRBrad Pitt 1/9/2016
567890MNOJennifer Lopez123456ABCJohn Doe  
258147PQRBrad Pitt555879LLLAngelina Jolie1/9/2016 
659874STUTom Cruise258147PQRBrad Pitt1/2/20191/9/2016
666454KLMSam Heughan456789JKLJulia Roberts  
888457FGHJoan Crawford659874STUTom Cruise 1/2/2019
985645DFDTom Hanks659874STUTom Cruise 1/2/2019
457896DNLWill Smith456789JKLJulia Roberts  
754699FSJDenzel Washington456789JKLJulia Roberts  
897333FDSGeorge Clooney666454KLMSam Heughan  

 

I want to use CALCULATETABLE to create a table from the Employee table to be used for RLS, and I only want to include active employees.


My issue is that some active employees have supervisors who are terminated. For one reason or another, the data is not updated, probably because a new supervisor has not yet been assigned to the area.

 

When I create the active employee table (using CalculateTable), if I exclude terminated employees, then I lose the record for the supervisors who are terminated, creating an issue in the PATH statement.

************************************************************************************************************************************

I am using the following to create the active table:

 

ACTIVE Employees = CALCULATETABLE('POC Mock Data',ISBLANK('POC Mock Data'[EMPLOYEE_TERMINATION_DATE]))

 

I then create a PATH statement as follows:

PATH = PATH('ACTIVE Employees'[EMPLOYEE_NUMBER],'ACTIVE Employees'[SUPERVISOR_EMPLOYEE_NUMBER])

 

I receive the following error for the PATH statement:

The value '555879LLL' in 'ACTIVE Employees'[SUPERVISOR_EMPLOYEE_NUMBER] must also exist in 'ACTIVE Employees'[EMPLOYEE_NUMBER]. Please add the missing data and try again.

 

Because I'm only including active employees in the ACTIVE Employees table, I am excluding records for any terminated supervisors.

 

Since I can't count on the consistent integrity of the employee table (outside of my domain), I'm trying to create an active table for which I can use the PATH statement for RLS.  Even if I have to exclude active records; that's ok, there shouldn't be that many.  To use the PATH statement, there must be a record in the table for all supervisors.

 

How do I dynamically create a table from the employee table that contains either:
Active employees OR
Terminated employees who are listed as the supervisor for an active employee

I only want to include a record in the table if the supervisor on that record also has a record in the table (confusing, I know).

 

I thought about creating a logical column titled "Supervisor for Active Employee", so I could then create the active table by filtering on employee termination date and the logical column. However, I ran into a myriad of issues trying to do this, primarily because a supervisor can be listed for many employees (I used lookupvalue which is inconclusive when you have multiple records that meet the lookup criteria). I couldn't think of any other way to do it.

 

I also created a table of unique supervisor employee numbers and tried to run that back against the employee table, but I ran into circular issues there.

 

I've tried a slew of other things, too many to list here.

 

Any help would be appreciated!  Thanks.

 

 

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@ConnieMaldonado,

 

Try this solution. I added a few rows to the sample data.

 

Calculated column in table All Employees:

 

Include in RLS = 
VAR vEmpNum = 'All Employees'[EMPLOYEE_NUMBER]
VAR vTable =
    FILTER (
        'All Employees',
        'All Employees'[SUPERVISOR_EMPLOYEE_NUMBER] = vEmpNum
            && ISBLANK ( 'All Employees'[EMPLOYEE_TERMINATION_DATE] )
    )
VAR vResult =
    IF ( ISBLANK ( 'All Employees'[EMPLOYEE_TERMINATION_DATE] ) || COUNTROWS ( vTable ), 1 )
RETURN
    vResult

 

DataInsights_0-1657635601226.png

 

 

Calculated table:

 

Active Employees = 
CALCULATETABLE ( 'All Employees', 'All Employees'[Include in RLS] = 1 )

 

DataInsights_1-1657635667281.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
DataInsights
Super User
Super User

@ConnieMaldonado,

 

Try this solution. I added a few rows to the sample data.

 

Calculated column in table All Employees:

 

Include in RLS = 
VAR vEmpNum = 'All Employees'[EMPLOYEE_NUMBER]
VAR vTable =
    FILTER (
        'All Employees',
        'All Employees'[SUPERVISOR_EMPLOYEE_NUMBER] = vEmpNum
            && ISBLANK ( 'All Employees'[EMPLOYEE_TERMINATION_DATE] )
    )
VAR vResult =
    IF ( ISBLANK ( 'All Employees'[EMPLOYEE_TERMINATION_DATE] ) || COUNTROWS ( vTable ), 1 )
RETURN
    vResult

 

DataInsights_0-1657635601226.png

 

 

Calculated table:

 

Active Employees = 
CALCULATETABLE ( 'All Employees', 'All Employees'[Include in RLS] = 1 )

 

DataInsights_1-1657635667281.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon & SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.