OpenBI Docs Buy

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> )
ParameterTypeDescription
expressionExpressionWhat is worked out at the axis's top level. Left out, COLLAPSEALL is a filter of CALCULATE.
axisAxisThe 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 COLLAPSE taken 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]
YearQuarterLitersAllShare
202511005000.2
202521205000.24
2025(blank)2205000.44
202611305000.26
202621505000.3
2026(blank)2805000.56
(blank)(blank)5005001

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]
ProductYearLitersBoth years
IPA202560140
IPA202680140
IPA(blank)140140
Pils2025100220
Pils2026120220
Pils(blank)220220
(blank)2025160360
(blank)2026200360
(blank)(blank)360360

COLLAPSE, EXPANDALL, LOOKUPWITHTOTALS, DIVIDE.

Last updated · OpenBI Studio 0.3.74