Dax Function: PATHITEMREVERSE
Category: Parent and Child Functions
The PATHITEMREVERSE function in Power BI is a DAX function used to retrieve a specific item from a hierarchical path, starting from the end of the path. It provides flexibility to navigate hierarchies in reverse order.
Purpose
The primary purpose of the PATHITEMREVERSE function is to facilitate hierarchical analysis by accessing levels in a path from the last node backward. It is particularly useful in scenarios where the hierarchy’s depth varies, and you need to analyze or extract data from the end.
Type of Calculations it Performs
Extracts specific nodes from hierarchical paths in reverse order.
Supports navigation through variable-depth hierarchies.
Practical Use Cases
Determining the most immediate supervisor in an organizational hierarchy.
Extracting the deepest level (e.g., subcategories) in a product hierarchy.
Identifying the last-accessed folder or file in a path.
PATHITEMREVERSE(<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) to retrieve from the end of the path. |
[datatype] | Optional | Determines the return data type: INTEGER or TEXT (default is TEXT). |
How Does PATHITEMREVERSE Dax Works
The PATHITEMREVERSE function:
Counts the levels in the hierarchical path.
Determines the node corresponding to the specified reverse
position.Returns the value at that position in the specified format (
TEXTorINTEGER).
Example Formula
If EmployeePath is 1,2,3,4:
PATHITEMREVERSE(Employee[EmployeePath], 1) // Returns "4"
PATHITEMREVERSE(Employee[EmployeePath], 2, INTEGER) // Returns 3 as an integerWhat Does It Return?
The function returns:
The value at the specified reverse position in the path, either as a string (
TEXT) or numeric value (INTEGER).
When Should We Use It?
When analyzing data from the bottom of a hierarchy upward.
In scenarios where hierarchical depth varies across entities.
For reverse-order comparisons or navigation.
Examples
Basic Usage :
Retrieve the last node from a path:
PATHITEMREVERSE("1,2,3,4", 1) // Returns "4"
Column Usage
Create a calculated column to display the immediate supervisor:
ImmediateSupervisor = PATHITEMREVERSE(Employee[EmployeePath], 2, INTEGER)
Advanced Usage
Combine with PATHLENGTH to dynamically extract levels:
DynamicReverseLevel = PATHITEMREVERSE(Employee[EmployeePath], PATHLENGTH(Employee[EmployeePath]) - 2)
Tips and Tricks
Understanding Reverse Indexing: The
positionparameter starts from1, where1is the last node.Consistent Delimiters: Ensure paths are properly formatted with commas.
Data Type Alignment: Use
[datatype]to standardize results across calculations.
Potential Pitfalls
Specifying a
positiongreater than the path length results in an error.Incorrect or inconsistent path formats can lead to unexpected outputs.
Performance Impact of PATHITEMREVERSE DAX Function:
Pre-compute paths with
PATHfor optimal performance.Use in conjunction with filters to limit large dataset calculations.
Related Functions You Might Need
PATH: Generates hierarchical paths.
PATHITEM: Retrieves nodes from the beginning of a path.
PATHLENGTH: Counts levels in a path.
Want to Learn More?
For more information, check out the official Microsoft documentation for PATHITEMREVERSE 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.
It retrieves a specific node from the end of a hierarchical path.
It is 1-based, meaning positions start from 1 at the end of the path.
The function returns an error.
Yes, by specifying the [datatype] parameter as INTEGER.
No, it works with paths formatted using commas as delimiters.