Skip to content

hierarchy.item ​

Returns the top-level element at a position in a hierarchy.

It only counts elements at the top level, not the elements below them. It's the reverse of hierarchy.position. To list the elements below one of them, use hierarchy.descendants.

js
hierarchy.item(dimension, hierarchy, index)

Parameters ​

ParameterTypeDescription
dimensionstringThe dimension's name.
hierarchystringThe hierarchy's name.
indexnumberThe element's position among the top-level elements, starting at 0.

Returns ​

string

The element's name, or an empty string when the position is out of range or the dimension or hierarchy can't be found.

Examples ​

List the top-level elements ​

js
let i = 0;
let name;
while ((name = hierarchy.item("Time", "Default", i)) !== "") {
    console.log(i + ": " + name);
    i++;
}
text
FY2025
	Q1
		Jan
		Feb
		Mar
	Q2
		Apr
		May
		Jun
FY2026
	Q1-26
		Jan26
Memo
text
0: FY2025
1: FY2026
2: Memo

Q1, Jan and the other elements below the top level aren't counted, and hierarchy.item("Time", "Default", 3) returns "".