# 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="https://3148043601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FL43fiRbeRtPnTjMpbGNO%2Fuploads%2Fgit-blob-b840fb8323fb34af77e8cad69cb9ff571ae9eb4b%2Fgrafik%20(215).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3148043601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FL43fiRbeRtPnTjMpbGNO%2Fuploads%2Fgit-blob-33ed4ab42e4476dad10c6573eaaba0031618c435%2Fgrafik%20(55).png?alt=media" 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="https://3148043601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FL43fiRbeRtPnTjMpbGNO%2Fuploads%2Fgit-blob-84c4a509e37887acc5c2526ae035a05de7cf0596%2Fgrafik%20(214).png?alt=media" 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="https://3148043601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FL43fiRbeRtPnTjMpbGNO%2Fuploads%2Fgit-blob-f323855ff984bbc840cb0207e23d1cd57cf035d7%2Fgrafik%20(210).png?alt=media" alt=""><figcaption></figcaption></figure>
