---
url: /process-functions/hierarchy-unwind.md
description: Removes an element, and everything below it, from a hierarchy.
---

# hierarchy.unwind

Removes an element, and everything below it, from a hierarchy.

What it does:

* Removes the element from every parent it has in the hierarchy, or from the top level.
* Removes everything below it too. Anything that's also under a parent outside this branch stays there.
* Deletes any parents it removes.
* Keeps leaf elements in the dimension. If a leaf isn't in another hierarchy, it becomes an orphan.

To take a leaf element out from under one parent, use [hierarchy.removeChild](/process-functions/hierarchy-removechild) instead. To remove a leaf element from the dimension altogether, including from every hierarchy, use [element.delete](/process-functions/element-delete).

::: warning
`hierarchy.unwind` is for parents and elements at the top level. For a leaf element under a parent it usually returns `"Error: Element not found."`, depending on how the leaf was added, so use [hierarchy.removeChild](/process-functions/hierarchy-removechild) for those.
:::

```js
hierarchy.unwind(dimension, hierarchy, element)
```

## Parameters

| Parameter | Type | Description |
|---|---|---|
| `dimension` | `string` | The dimension's name or id. |
| `hierarchy` | `string` | The hierarchy's name or id. |
| `element` | `string` | The element to remove, along with everything below it. |

## Returns

An empty string when it succeeds, or an error message when the dimension, hierarchy or element can't be found.

## Examples

```js
hierarchy.unwind("Account", "Profit and Loss", "EBITDA");
```

::: code-group

```text [Before]
Net Profit
	EBITDA
		Revenue
			600010
			600020
		Operating Expenses
			700010
	Depreciation
		800010
KPIs
	Revenue
		600010
		600020
```

```text [After]
Net Profit
	Depreciation
		800010
KPIs
	Revenue
		600010
		600020
```

:::

`EBITDA` and `Operating Expenses` are removed and deleted. `Revenue` stays under `KPIs`, because it also sits there. `700010` is no longer in the hierarchy, so if it isn't in another hierarchy it becomes an orphan.
