> Documentation index: https://www.gooddata.ai/docs/gooddata-ui/llms.txt lists every page of these docs as Markdown.

# Read attribute hierarchies

> Read attribute hierarchies from the workspace catalog, and list them from a dashboard plugin.

API reference: [ICatalogAttributeHierarchy](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-model/sdk-model.icatalogattributehierarchy/index.md) (interface), [IAttributeHierarchyMetadataObject](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-model/sdk-model.iattributehierarchymetadataobject/index.md) (interface)

An attribute hierarchy is a named, ordered list of attributes that describes a drill path — for example Country, then State, then City. Dashboards use a saved hierarchy to let viewers drill from one level to the next on a widget.

## [Read hierarchies from the catalog](https://www.gooddata.ai/docs/gooddata-ui/latest/data-layer/data-model/attribute-hierarchies/#read-hierarchies-from-the-catalog)

Saved hierarchies are catalog items. Load them the same way as measures and attributes — see [Load the workspace catalog at runtime](https://www.gooddata.ai/docs/gooddata-ui/latest/data-layer/data-model/workspace-catalog/index.md) — by including `"attributeHierarchy"` in `forTypes`, then read them off the loaded [`IWorkspaceCatalog`](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.iworkspacecatalog/index.md):

```ts
import { type IAnalyticalBackend } from "@gooddata/sdk-backend-spi";

export async function loadHierarchies(backend: IAnalyticalBackend, workspace: string) {
    const catalog = await backend.workspace(workspace).catalog().forTypes(["attributeHierarchy"]).load();

    return catalog.attributeHierarchies();
}
```

`catalog.attributeHierarchies()` returns every [`ICatalogAttributeHierarchy`](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-model/sdk-model.icatalogattributehierarchy/index.md) in the workspace. Use `catalog.availableAttributeHierarchies()` instead when you have already narrowed the catalog to items compatible with a specific measure or visualization (see [Offer only compatible items](https://www.gooddata.ai/docs/gooddata-ui/latest/data-layer/data-model/workspace-catalog/index.md#offer-only-compatible-items)).

Each [`ICatalogAttributeHierarchy`](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-model/sdk-model.icatalogattributehierarchy/index.md) wraps an [`IAttributeHierarchyMetadataObject`](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-model/sdk-model.iattributehierarchymetadataobject/index.md), which carries the ordered `attributes: ObjRef[]` — the drill path, from top level to bottom.

## [List hierarchies from a dashboard plugin](https://www.gooddata.ai/docs/gooddata-ui/latest/data-layer/data-model/attribute-hierarchies/#list-hierarchies-from-a-dashboard-plugin)

To list the hierarchies available in the workspace from inside a plugin, use the `@beta` selector `selectCatalogAttributeHierarchies` with [useDashboardSelector](https://www.gooddata.ai/docs/gooddata-ui/latest/dashboard-plugins/use-dashboard-selector/index.md):

```ts
import { selectCatalogAttributeHierarchies, useDashboardSelector } from "@gooddata/sdk-ui-dashboard";

const hierarchies = useDashboardSelector(selectCatalogAttributeHierarchies);
```

See [Dashboard component](https://www.gooddata.ai/docs/gooddata-ui/latest/dashboard-plugins/dashboard/index.md) for the rest of the dashboard selector surface.

## [Notes](https://www.gooddata.ai/docs/gooddata-ui/latest/data-layer/data-model/attribute-hierarchies/#notes)

- `attributes` on a hierarchy is ordered top to bottom. Reordering it changes the drill path, not just its membership.
