hierarchy.group
Adds a leaf element under a parent, creating either if they don't exist.
Use it for leaf elements, which are where values are stored. To nest an element that has children of its own, use hierarchy.structure.
js
hierarchy.group(dimension, hierarchy, parent, child, weight)Parameters
| Parameter | Type | Description |
|---|---|---|
dimension | string | The dimension's name or id. |
hierarchy | string | The hierarchy's name or id. |
parent | string | The parent element's name. Pass "" to add the child at the top level. |
child | string | The child element's name. |
weight | number | Optional. 1 to add the child into the parent, or -1 to subtract it. Defaults to 1. |
Returns
stringAn empty string when it succeeds, or an error message when it fails, such as when the link would be circular.
Examples
Add an element under a parent
js
hierarchy.group("Account", "Profit and Loss", "Total Revenue", "600010");Build a hierarchy
Use structure for the parent levels and group for the leaf elements under them.
js
// Parent levels
hierarchy.structure("Account", "Profit and Loss", "Net Profit", "Total Revenue");
hierarchy.structure("Account", "Profit and Loss", "Net Profit", "Total Expenses", -1); // Subtract expenses
// Leaf elements
hierarchy.group("Account", "Profit and Loss", "Total Revenue", "600010");
hierarchy.group("Account", "Profit and Loss", "Total Revenue", "600020");
hierarchy.group("Account", "Profit and Loss", "Total Expenses", "700010");text
Net Profit
├── Total Revenue
│ ├── 600010
│ └── 600020
└── Total Expenses (−1)
└── 700010Add a leaf at the top level
js
hierarchy.group("Account", "Profit and Loss", "", "Unallocated");