Slice
The rows of cube data at a selection of intersections.
js
// Cube: Sales. Dimensions: Year, Month, Scenario, Department, Product, Measures
const slice = cube.slice("Sales", "2017|2018", "", "Actual", "", "", "Units Sold");
for (const row of slice) {
console.log(row);
}Constructors
Both constructors pick the intersections the same way. Pass one value per dimension, in the cube's dimension order:
- One element:
"Actual" - Several elements: separated by
|, such as"2017|2018" - Every element:
"", which includes every element of that dimension with data
Instead of listing every dimension, you can pass an object keyed by dimension name ^v2.7.194. Dimensions you leave out default to "".
cube.slice cube.slice(cubeName, ...elements) Slice | null
Returns a slice of a cube's values, with formulas calculated. Returns null when the cube can't be found.
| Parameter | Type | Description |
|---|---|---|
cubeName | string | The cube's name. |
elements | string | string[] | object | The elements for each dimension, as separate arguments, an array, or an object keyed by dimension name. |
js
cube.slice("Sales", "2017|2018", "", "Actual", "", "", "Units Sold");
cube.slice("Sales", ["2017|2018", "", "Actual", "", "", "Units Sold"]);
cube.slice("Sales", { "Year": "2017|2018", "Scenario": "Actual", "Measures": "Units Sold" });cube.slice cube.slice(cubeName, ignoreConsolidations, ...elements) Slice | null
The same as above, with the option to leave out consolidated elements so only leaf-level intersections are returned.
| Parameter | Type | Description |
|---|---|---|
cubeName | string | The cube's name. |
ignoreConsolidations | boolean | true to return only leaf-level intersections. |
elements | string | string[] | object | The elements for each dimension, as separate arguments, an array, or an object keyed by dimension name. |
js
cube.slice("Sales", true, "2017|2018", "", "Actual", "", "", "Units Sold");cube.sliceStatic cube.sliceStatic(cubeName, ...elements) Slice | null
Returns a slice of a cube's stored values, without running formulas. Returns null when the cube can't be found.
| Parameter | Type | Description |
|---|---|---|
cubeName | string | The cube's name. |
elements | string | string[] | object | The elements for each dimension, as separate arguments, an array, or an object keyed by dimension name. |
js
cube.sliceStatic("Sales", "2017|2018", "", "Actual", "", "", "Units Sold");Overview
- Rows: each row is an array of the row's elements, one per dimension, followed by its value:
[element1, element2, ..., elementN, value]. - Reading rows: loop over the slice with
for...of^v2.7.194, or walk it with EOF() and Next().
Methods
Size Size() number
Returns the number of rows in the slice.
Next Next() array
Returns the next row and moves to the one after it.
EOF EOF() boolean
Returns true when there are no more rows.
GetIndex GetIndex() number
Returns the position of the current row, starting at 0.
Reset Reset()
Goes back to the first row, so the slice can be read again.
exportCsv exportCsv(filename, withHeaders, escapeControlCharacters) string
Writes the whole slice to a CSV file, with one column per dimension and a final value column. Returns the file's path.
| Parameter | Type | Description |
|---|---|---|
filename | string | The path of the file to write. |
withHeaders | boolean | true to write a heading row. |
escapeControlCharacters | boolean | Optional. true to escape control characters in values. |
Examples
Loop over the rows ^v2.7.194
js
// Cube: Sales. Dimensions: Year, Month, Scenario, Department, Product, Measures
const slice = cube.slice("Sales", "2017|2018", "", "Actual", "", "", "Units Sold");
for (const row of slice) {
console.log(row);
}Walk the rows one at a time
js
const slice = cube.slice("Sales", "2017|2018", "", "Actual", "", "", "Units Sold");
while (!slice.EOF()) {
const row = slice.Next();
console.log(row);
}Pick dimensions by name ^v2.7.194
js
const slice = cube.slice("Sales", {
"Year": "2017|2018",
"Scenario": "Actual",
"Measures": "Units Sold"
});Export to CSV
js
const slice = cube.slice("Sales", "2017|2018", "", "Actual", "", "", "Units Sold");
slice.exportCsv("exports/sales_slice.csv", true);