Skip to content

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 ​

ParameterTypeDescription
dimensionstringThe dimension's name or id.
hierarchystringThe hierarchy's name or id.
parentstringThe parent element's name. Pass "" to add the child at the top level.
childstringThe child element's name.
weightnumberOptional. 1 to add the child into the parent, or -1 to subtract it. Defaults to 1.

Returns ​

string

An 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)
    └── 700010

Add a leaf at the top level ​

js
hierarchy.group("Account", "Profit and Loss", "", "Unallocated");