Use slicer to filter PATHCONTAINS

So I have a table with employees. Each employee has a manager, and using the PATH function, I can create another column, that traces the management of each employee to the CEO (using employee ID and manager's ID.) For example, if my boss reports to the ceo, my employee path would be "CEO ID | My boss ID | My ID" or "10001234|10002345|1000456."

Once I have this path selected, I need to be able to filter my data based on a list of people (business leaders.) If I select business leader A, then I want my data to only include people who have business leader A in their employee path, i.e., people who eventually report to him. I have a separate table of business leaders. Here's what Im doing:

  1. Create a path for each employee: empPath = PATH(EmployeeTable[Employee ID], EmployeeTable[Manager ID])
  2. Use business leader table as a slicer (using their IDs)
  3. Create a variable, selectedLeader, that records the value of whatever selection has been made from the slicer: selectedLeader = IF(HASONEVALUE('LeaderTable'[Id]),VALUES('LeaderTable'[Id]),BLANK())
  4. Put it all together using PATHCONTAINS to filter assign a binary indicator that will allow us to filter the data:
Filter = 
var selectedLeader = IF(HASONEVALUE('LeaderTable'[Id]),VALUES('LeaderTable'[Id]),BLANK())
var empPath = PATH(EmployeeTable[Employee ID], EmployeeTable[Manager ID])
    return IF(PATHCONTAINS(empPath, selectedLeader ),1,0)

This however, gives the error: Calculation error in measure: A table of multiple values was supplied where a single value was expected.

I've been trying to play around with the formula a lot, using VALUES, FIRSTNONBLANK and other aggregating functions on employeePath, but none are working as desired. Any help appreciated!


The issue is that you need row context for your PATH function to work as you're expecting. As you have it written, it doesn't know which row of the EmployeeTable you're referring to with empPath.

Try this instead:

Filter = 
VAR selectedLeader = SELECTEDVALUE ( 'LeaderTable'[Id] )
VAR FilteredTable =
    FILTER (
        EmployeeTable,
        PATHCONTAINS (
            PATH ( EmployeeTable[Employee ID], EmployeeTable[Manager ID] ),
            selectedLeader
        )
    )
RETURN
    IF ( ISEMPTY ( FilteredTable ), 0, 1 )

You can make this more efficient if you define a calculated path column on the EmployeeTable first.

Path = PATH ( EmployeeTable[Employee ID], EmployeeTable[Manager ID] )

Then the measure simplifies to:

Filter =
VAR selectedLeader = SELECTEDVALUE ( 'LeaderTable'[Id] )
VAR FilteredTable =
    FILTER ( EmployeeTable, PATHCONTAINS ( EmployeeTable[Path], selectedLeader ) )
RETURN
    IF ( ISEMPTY ( FilteredTable ), 0, 1 )