---
url: /process-functions/hierarchy-structure.md
description: Nests one parent element under another, creating either if they don't exist.
---

# hierarchy.structure

Nests one parent element under another, creating either if they don't exist.

Use it to build the parent levels of a hierarchy, and [hierarchy.group](/process-functions/hierarchy-group) for the leaf elements under them.

```js
hierarchy.structure(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. |
| `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

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.structure("Account", "Profit and Loss", "EBITDA", "Total Revenue");
```

### Build a hierarchy

Use `structure` for the parent levels and `group` for the leaf elements under them.

::: code-group

```js [build.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 [Result]
Net Profit
├── Total Revenue
│   ├── 600010
│   └── 600020
└── Total Expenses (−1)
    └── 700010
```

:::
