---
url: /set-instructions/in-scripts.md
description: >-
  The set instructions that cube.crosstab and dimension.set accept, written as
  code.
---

# Set Instructions in Scripts

[cube.crosstab](/process-functions/cube-crosstab) and [dimension.set](/process-functions/dimension-set) take set instructions as an array, run in order, the same as a Workview set.

```js
dimension.set("Region", [{ set: ["All Regions"] }, "expand-all", "use-alias:Description"]);
```

## Writing instructions

* **Selecting elements:** `{ set: ["All Regions", "North"] }`. Add `hierarchy` to take them from a named hierarchy: `{ set: ["2026"], hierarchy: "Fiscal" }`. To choose a hierarchy for each element separately, use `{ name, hierarchy }` objects: `{ set: [{ name: "2026", hierarchy: "Fiscal" }] }`.
* **Actions:** plain strings, such as `"expand-all"`.
* **Actions with an argument:** the code, a colon, then the argument, such as `"use-alias:Description"`.
* **Next-instruction actions:** `expand-next`, `collapse-next` and `remove` apply to the `set` that follows them.

## Instructions

| Code | Instruction | Argument |
|---|---|---|
| `expand` | [Expand](/set-instructions/expand) | |
| `expand-all` | [Expand All](/set-instructions/expand-all) | |
| `expand-above` | [Reverse Subtotals](/set-instructions/reverse-subtotals-at-the-bottom) | Put it before the expand. |
| `expand-next` | [Expand Next Instruction](/set-instructions/expand-next-instruction) | |
| `collapse-next` | [Collapse Next Instruction](/set-instructions/collapse-next-instruction) | |
| `remove` | [Remove Using The Next Instruction](/set-instructions/remove-items-using-the-next-instruction) | |
| `remove-all-consolidations` | [Remove Consolidations](/set-instructions/remove-consolidations) | |
| `remove-n-level` | Remove Leaf Elements | |
| `remove-duplicates` | Remove Duplicates | |
| `sort-by-name` | [Sort By Name Ascending](/set-instructions/sort-by-name-ascending) | |
| `sort-by-name-desc` | [Sort By Name Descending](/set-instructions/sort-by-name-descending) | |
| `insert-next` | [Insert The Next Element](/set-instructions/insert-the-next-element-from-a-hierarchy) | Hierarchy name |
| `insert-previous` | [Insert The Previous Element](/set-instructions/insert-the-previous-element-from-a-hierarchy) | Hierarchy name |
| `insert-variable` | [Insert A Variable Value](/set-instructions/inserts-a-variable-value-into-the-working-set) | Variable name |
| `use-alias` | [Set The Alias](/set-instructions/set-the-alias-for-the-set) | Alias name |
| `indent` | [Indent](/set-instructions/indent) | |
| `reset-indents` | [Reset Indents](/set-instructions/reset-indents) | |

::: info Workview-only instructions
Other set instructions are accepted but do nothing in a script. These include formatting, styles, suppression, sorting or grouping by value, blank spaces, formulas and variances. To leave out empty rows in a crosstab, use its `suppress` option.
:::

## Examples

::: code-group

```js [regions.js]
// All regions except South
const regions = dimension.set("Region", [
    { set: ["All Regions"] },
    "expand",
    "remove",
    { set: ["South"] }
]);
```

```js [Result]
[
    { name: "All Regions", label: "All Regions", hierarchy: "Default", level: 0, consolidation: true },
    { name: "North", label: "North", hierarchy: "Default", level: 1, consolidation: false }
]
```

:::
