DAX Parent & Child - PATH function



Description

Returns a delimited text string with the identifiers of all the parents of the current identifier, starting with the oldest and continuing until the current identifier.

Syntax

PATH (<ID_columnName>, <parent_columnName>) 

Parameters

Sr.No. Parameter & Description
1

ID_columnName

The name of an existing column containing the unique identifier for rows in the table.

This cannot be an expression.

The data type of the value in ID_columnName must be text or integer, and must be the same data type as the column referenced in parent_columnName.

2

parent_columnName

The name of an existing column containing the unique identifier for the parent of the current row.

This cannot be an expression.

The data type of the value in parent_columnName data type must be a text or an integer, and must be the same data type as the value in ID_columnName.

Return Value

A delimited text string containing the identifiers of all the parents to the current identifier.

Remarks

DAX PATH function is used in tables that have some kind of internal hierarchy, to return the items that are related to the current row value.

For example, suppose you have a table Employees that contains the details of employees in an organization. The table contains −

  • Employee ID of employees.
  • Employee ID of the managers of employees.
  • Employee ID of the managers of the managers.

You can use DAX PATH function to return the path that connects an employee to his or her manager.

The path is not constrained to a single level of parent-child relationships. It can return related rows that are several levels up from the specified starting row, i.e., the path that connects an employee to his or her manager’s manager.

  • The delimiter used to separate the ascendants is the vertical bar, '|'.

  • The values in ID_columnName and parent_columnName must have the same data type, text, or integer.

  • Values in parent_columnName must be present in ID_columnName. That is, you cannot look up a parent, if there is no value at the child level.

  • If parent_columnName is BLANK then PATH () returns ID_columnName value. In other words, if you look for the manager of an employee but the parent_columnName column has no data, the PATH function returns just the employee ID.

  • If ID_columnName has duplicates and parent_columnName is the same for those duplicates, then PATH () returns the common parent_columnName value. However, if parent_columnNamevalue is different for those duplicates then PATH () returns an error. In other words, if you have two listings for the same employee ID and they have the same manager ID, the PATH function returns the ID for that manager. However, if there are two identical employee IDs that have different manager IDs, PATH function returns an error.

  • If ID_columnName is BLANK, then PATH () returns BLANK.

  • If ID_columnName contains a vertical bar '|' then PATH () returns an error.

Example

= PATH (Employee[EmployeeID], Employee[ManagerEmployeeID]) 

This DAX formula returns a calculated column containing the delimited strings of EmployeeIDs of all the managers in the hierarchy above each employee starting from the topmost employee.

For example, OrgEmp0001|OrgEmp0002|OrgEmp0006|OrgEmp0015 is the PATH returned for an employee with ID OrgEmp0015, where the reporting hierarchy is OrgEmp0015 → OrgEmp0006 → OrgEmp0002 → OrgEmp0001.

dax_functions_parent_child
Advertisements