# RANGETOHIERARCHY

#### Syntax

**RANGETOHIERARCHY**(*range;* *numLevels; numExpandLevels*)

1. *range* - the range containing the hierarchy information - ***Value type**: range*
2. *numLevels* - the number of columns at the beginning of range defining the hierarchy - ***Value type**: number*
3. *numExpandedLevels* - the number of levels of the hierarchy which should be expanded - ***Value type**: number (optional, default value: numLevels)*
4. *aggregationType* - specifies how empty values in the additional columns of the hierarchy should be aggregated - ***Value type**: text (optional, default value: “none”)*\
   Possible values are:
   1. "none" - no additional aggregation
   2. "sum" - using the sum of the children
   3. "min" - using the minimum value of the children
   4. "max" - using the maximum of the children
   5. "avg" - using the average value of the children

#### Return

The result is a range with

* the hierarchy level in the first column
* the display name in the next column (extracted from the first *numLevels* columns of *range*)
* all remaining columns of *range*
* all levels up to *numExpandedLevels* are expanded, all other levels are collapsed

#### Examples

In the following examples, the widget on the left is a table widget of type "Hierarchy".

*Example 1* - The whole table is used as hierarchy.

<figure><img src="/files/AILEg4adTd0o6UNxpcjA" alt=""><figcaption></figcaption></figure>

*Example 2* - like example 1, but with an additional column containing values for the hierarchy.

<figure><img src="/files/19OogwCu7qMwP9Go6pWx" alt=""><figcaption></figcaption></figure>

*Example 3* - The hierarchy is only defined by the first 3 columns. The remaining 2 columns are added to each row of the hierarchy.

<figure><img src="/files/sZGboPVYK6KgRSZELfTa" alt=""><figcaption></figcaption></figure>

*Example 4* - Parameter 3 specifies that only the first two levels of the hierarchy are expanded by default.

<figure><img src="/files/oiFMb4Zc2xyPcciPyufd" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nedyx.com/nedyx/clearlines-functions/range-functions/rangetohierarchy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
