PATHITEM

The PATHITEM function returns the item that occupies the indicated position in a string resulting from executing the PATH function, being the positions counted from left to right.

Syntax

PATHITEM(
    path,
    position
    [, type]
)

Parameters
  • path: Text string returned by the PATH function.
  • position: Integer indicating the position of the element to be returned, counting the positions from left to right starting with 1.
  • type: (Optional argument) Value that defines the type of the returned value: TEXT (or 0) if you want the result to be returned as a text string (default value) or INTEGER (or 1) if you want the result to be returned as an integer.
Returned value

The PATHITEM function returns a text string or an integer.

Additional Information

Positions are counted from left to right. The leftmost item in the list -corresponding to the farthest parent element- occupies position 1.

If a position less than 1 or greater than the number of elements in the path is specified, the function returns Blank.

If the indicated type is invalid, the function returns an error.

Examples

We start from the following table:

Functions of parents and children. Data table

This table contains worker identifiers and the hierarchical relationship between them. The scheme of this hierarchy is shown in the following figure:

Functions of parents and children. Hierarchy

Once the path of each employee has been obtained, we can extract the item that occupies the position located at the extreme left -the one corresponding to the farthest parent element- with the following calculated column:

pathitem_1 = PATHITEM(Employees[path], 1)

PATHITEM function. Example of use

In this case, the type of the values to be returned has not been specified, so the function opts for the default option and returns texts. The function returns the furthest parent element for all elements (employee 112). In the case of the employee with this identifier -employee who does not have hierarchical superiors- the function returns the same identifier.

If we repeat the process indicating position 2 we obtain the following result:

pathitem_2 = PATHITEM(Employees[path], 2, INTEGER)

PATHITEM function. Example of use

In this case we have specified that the result is returned as an integer. Note how the value corresponding to element 112 (which has no parent elements) is a Blank.

Category
Parent and child
Submitted by admin on Tue, 01/29/2019 - 11:47