Dax Function: PATHITEM
Category: Parent and Child Functions
The PATHITEM function in Power BI is a DAX function used to extract a specific item from a hierarchical path generated by the PATH function. It identifies and returns a node at a specified position in the path.
Purpose
The primary purpose of the PATHITEM function is to enable analysis and navigation of hierarchical structures by isolating specific levels within a path. It simplifies accessing individual nodes or entities within a hierarchical path.
Type of Calculations it Performs
Retrieves a specific element (node) from a delimited string (path).
Supports hierarchical analysis by isolating levels dynamically.
Practical Use Cases
Extracting direct managers or supervisors from organizational hierarchies.
Identifying specific levels in product categories or folder structures.
Simplifying hierarchical data for visualization and reporting.
PATHITEM(<path>, <position>, [<datatype>])</datatype></position></path>
| Parameter | Type | Description |
|---|---|---|
path | Column | A column or calculated value containing the hierarchical path string. |
position | Integer | Specifies the position (level) of the node to retrieve from the path. |
[datatype] | Optional | Determines the return data type: INTEGER or TEXT (default is TEXT). |
How Does PATHITEM Dax Works
The PATHITEM function:
Splits the hierarchical path into individual components based on the delimiter (default is a comma
,).Extracts the node at the specified
position.Converts the result to the specified
datatypeif provided.
Example Formula
If EmployeePath is a column containing 1,2,3,4:
PATHITEM(Employee[EmployeePath], 2) // Returns "2"
PATHITEM(Employee[EmployeePath], 2, INTEGER) // Returns 2 as an integerWhat Does It Return?
The function returns a single value:
The value at the specified position in the path, either as a string (
TEXT) or a numeric value (INTEGER).
When Should We Use It?
Analyzing or reporting specific hierarchical levels.
Creating drill-downs or summaries for a particular hierarchy depth.
Filtering rows based on a level in the hierarchy.
Examples
Basic Usage :
Retrieve the second node from a path:
PATHITEM("1,2,3,4", 2) // Returns "2"
Column Usage
Create a calculated column to display the manager (second level) for each employee:
ManagerID = PATHITEM(Employee[EmployeePath], 2, INTEGER)
Advanced Usage
Combine with conditional logic to flag specific levels:
IsSeniorManager = IF(PATHITEM(Employee[EmployeePath], 3, INTEGER) = 200, TRUE(), FALSE())
Tips and Tricks
Data Type Awareness: Use the
[datatype]parameter to ensure consistent formatting.Indexing: The
positionparameter is 1-based (starts from 1).Delimiter Consistency: The function works with paths using commas; ensure paths are formatted correctly.
Potential Pitfalls
Invalid
positionvalues (e.g., negative or exceeding the path length) return errors.Handling paths with inconsistent delimiters or formats can cause incorrect results.
Performance Impact of PATHITEM DAX Function:
Use with precomputed paths (
PATH) to avoid redundant calculations.Avoid complex calculations on very large datasets to maintain performance.
Related Functions You Might Need
PATH: Generates hierarchical paths.
PATHCONTAINS: Checks if a specific value exists in a path.
PATHLENGTH: Determines the number of levels in a path.
Want to Learn More?
For more information, check out the official Microsoft documentation for PATHITEM You can also experiment with this function in your Power BI reports to explore its capabilities.
Unlock the full capabilities of Power BI and elevate your data insights with our specialized consulting services. Whether you need guidance on advanced DAX functions like those highlighted here, support in designing interactive dashboards, or expertise in optimizing data models for enhanced performance, our experienced Power BI consultants are equipped to deliver customized solutions for your business. Explore our Power BI Consulting Services page to discover how we can help your organization make smarter, data-driven decisions.
The PATHITEM function extracts a specific node from a hierarchical path.
It is 1-based, meaning positions start from 1.
The function returns an error.
Yes, by specifying the [datatype] parameter as INTEGER.
No, it works with paths formatted using commas as delimiters.