COLLAPSEALL
In a visual calculation, an expression evaluated at the top level of an axis.
A visual calculation works on the table behind a visual: a row for each group on the visual's axes and one for each of their totals. To try one in the OAX view, give a table that shape with DEFINE TABLE ... WITH VISUAL SHAPE: its axes, their groups, the TRUE/FALSE column that marks each group's totals and the order, and with DENSIFY a name for the column that marks rows the shape fills in. Then write the calculation as a COLUMN of that table, as Power BI's own queries do. The examples below are queries of that kind, small enough to check by hand.
Group: Window and visual calculations. Compatible with DAX.
Syntax
COLLAPSEALL ( <expression>, <axis> )
COLLAPSEALL ( <axis> )
| Parameter | Type | Description |
|---|---|---|
expression | Expression | What is worked out at the axis's top level. Left out, COLLAPSEALL is a filter of CALCULATE. |
axis | Axis | The axis whose total is wanted: ROWS, COLUMNS, or several, as ROWS COLUMNS. |
Returns
Same type as the expression. The expression's value at the axis's total.
Remarks
- On every row it gives the axis's grand total for that row's place on the other axes: with products on the rows and years on the columns,
COLLAPSEALL ( [Liters], ROWS )is the year's total over all products. DIVIDE ( [Liters], COLLAPSEALL ( [Liters], ROWS ) )is each row's share of the grand total, whatever its level.- It is
COLLAPSEtaken as far up as it goes. - It works only in a visual calculation; in a measure, a calculated column or a plain query it is an error.
Examples
Share of the grand total
DEFINE
TABLE Visual =
DATATABLE (
"Year", INTEGER, "Quarter", INTEGER, "Liters", INTEGER, "All years", BOOLEAN, "All quarters", BOOLEAN,
{
{ 2025, 1, 100, FALSE, FALSE }, { 2025, 2, 120, FALSE, FALSE }, { 2025, BLANK (), 220, FALSE, TRUE },
{ 2026, 1, 130, FALSE, FALSE }, { 2026, 2, 150, FALSE, FALSE }, { 2026, BLANK (), 280, FALSE, TRUE },
{ BLANK (), BLANK (), 500, TRUE, TRUE }
}
)
WITH VISUAL SHAPE
AXIS ROWS
GROUP [Year] TOTAL [All years]
GROUP [Quarter] TOTAL [All quarters]
ORDER BY [Year], [Quarter]
DENSIFY "Added"
COLUMN Visual[All] = COLLAPSEALL ( [Liters], ROWS )
COLUMN Visual[Share] = DIVIDE ( [Liters], COLLAPSEALL ( [Liters], ROWS ) )
EVALUATE
SELECTCOLUMNS (
Visual,
"Year", [Year], "Quarter", [Quarter], "Liters", [Liters],
"All", [All],
"Share", [Share]
)
ORDER BY ISBLANK ( [Year] ), [Year], ISBLANK ( [Quarter] ), [Quarter]
| Year | Quarter | Liters | All | Share |
|---|---|---|---|---|
| 2025 | 1 | 100 | 500 | 0.2 |
| 2025 | 2 | 120 | 500 | 0.24 |
| 2025 | (blank) | 220 | 500 | 0.44 |
| 2026 | 1 | 130 | 500 | 0.26 |
| 2026 | 2 | 150 | 500 | 0.3 |
| 2026 | (blank) | 280 | 500 | 0.56 |
| (blank) | (blank) | 500 | 500 | 1 |
The total of the other axis
Products on the rows, years on the columns: collapsing the columns gives each product's total over both years.
DEFINE
TABLE Visual =
DATATABLE (
"Product", STRING, "Year", INTEGER, "Liters", INTEGER, "All products", BOOLEAN, "All years", BOOLEAN,
{
{ "IPA", 2025, 60, FALSE, FALSE }, { "IPA", 2026, 80, FALSE, FALSE }, { "IPA", BLANK (), 140, FALSE, TRUE },
{ "Pils", 2025, 100, FALSE, FALSE }, { "Pils", 2026, 120, FALSE, FALSE }, { "Pils", BLANK (), 220, FALSE, TRUE },
{ BLANK (), 2025, 160, TRUE, FALSE }, { BLANK (), 2026, 200, TRUE, FALSE }, { BLANK (), BLANK (), 360, TRUE, TRUE }
}
)
WITH VISUAL SHAPE
AXIS ROWS GROUP [Product] TOTAL [All products] ORDER BY [Product]
AXIS COLUMNS GROUP [Year] TOTAL [All years] ORDER BY [Year]
DENSIFY "Added"
COLUMN Visual[Both years] = COLLAPSEALL ( [Liters], COLUMNS )
EVALUATE
SELECTCOLUMNS (
Visual,
"Product", [Product], "Year", [Year], "Liters", [Liters],
"Both years", [Both years]
)
ORDER BY ISBLANK ( [Product] ), [Product], ISBLANK ( [Year] ), [Year]
| Product | Year | Liters | Both years |
|---|---|---|---|
| IPA | 2025 | 60 | 140 |
| IPA | 2026 | 80 | 140 |
| IPA | (blank) | 140 | 140 |
| Pils | 2025 | 100 | 220 |
| Pils | 2026 | 120 | 220 |
| Pils | (blank) | 220 | 220 |
| (blank) | 2025 | 160 | 360 |
| (blank) | 2026 | 200 | 360 |
| (blank) | (blank) | 360 | 360 |