OpenBI Docs Buy

RUNNINGSUM

In a visual calculation, the sum of a column from the first row along an axis to the current one.

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

RUNNINGSUM ( <column> [, <axis>] [, <orderBy>] [, <blanks>] [, <reset>] )
ParameterTypeDescription
columnColumnA field of the visual, such as [Liters]. An expression is not allowed here: make it a visual calculation of its own and name that.
axisAxis
optional
Which way to go: ROWS or COLUMNS, or both, as ROWS COLUMNS, which goes down the rows first and then across the columns; ROWPAGES for small multiples. Left out, the visual's first axis.
orderByORDERBY
optional
ORDERBY ( ... ) to take the rows in another order than the axis has.
blanksKeyword
optional
With an ORDERBY: where blank values go, DEFAULT, FIRST or LAST.
resetReset
optional
Where it starts again: NONE (when left out) never; HIGHESTPARENT (or 1, or the axis's top column) at each value of the top group; LOWESTPARENT (or -1) at each row's own parent; another whole number, or a column of the axis, at that level.

Returns

Number. The total of the column from the first row along the axis to the current one.

Remarks

  • Each level of the visual is walked on its own: the quarters' rows among the quarters, the years' subtotals among the years, the grand total by itself. Without a reset the quarters' total runs on from 2025 into 2026; with HIGHESTPARENT it starts again each year.
  • A blank value adds nothing: that row shows the total so far.
  • With ORDERBY, the rows are added in that order instead of the axis's. A reset and an ORDERBY can't be given together.
  • To add up an expression, make it a visual calculation first and run the sum on that one: COLUMN Visual[Double] = [Liters] * 2, then RUNNINGSUM ( [Double] ).
  • It works only in a visual calculation; in a measure, a calculated column or a plain query it is an error.

Examples

Running total of four months

The shape says: months on the rows, in month order, and no totals.

DEFINE
    TABLE Visual =
        DATATABLE (
            "Month", INTEGER, "Liters", INTEGER,
            { { 1, 100 }, { 2, 150 }, { 3, 120 }, { 4, 90 } }
        )
        WITH VISUAL SHAPE
            AXIS ROWS GROUP [Month] ORDER BY [Month]
            DENSIFY "Added"
    COLUMN Visual[Running] = RUNNINGSUM ( [Liters] )
EVALUATE
SELECTCOLUMNS (
    Visual,
    "Month", [Month], "Liters", [Liters],
    "Running", [Running]
)
ORDER BY [Month]
MonthLitersRunning
1100100
2150250
3120370
490460

Restarting each year

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[Running] = RUNNINGSUM ( [Liters] )
    COLUMN Visual[Within the year] = RUNNINGSUM ( [Liters], HIGHESTPARENT )
EVALUATE
SELECTCOLUMNS (
    Visual,
    "Year", [Year], "Quarter", [Quarter], "Liters", [Liters],
    "Running", [Running],
    "Within the year", [Within the year]
)
ORDER BY ISBLANK ( [Year] ), [Year], ISBLANK ( [Quarter] ), [Quarter]
YearQuarterLitersRunningWithin the year
20251100100100
20252120220220
2025(blank)220220220
20261130350130
20262150500280
2026(blank)280500280
(blank)(blank)500500500

From the largest month down

DEFINE
    TABLE Visual =
        DATATABLE (
            "Month", INTEGER, "Liters", INTEGER,
            { { 1, 100 }, { 2, 150 }, { 3, 120 }, { 4, 90 } }
        )
        WITH VISUAL SHAPE
            AXIS ROWS GROUP [Month] ORDER BY [Month]
            DENSIFY "Added"
    COLUMN Visual[Largest first] = RUNNINGSUM ( [Liters], ORDERBY ( [Liters], DESC ) )
EVALUATE
SELECTCOLUMNS (
    Visual,
    "Month", [Month], "Liters", [Liters],
    "Largest first", [Largest first]
)
ORDER BY [Month]
MonthLitersLargest first
1100370
2150150
3120270
490460

MOVINGAVERAGE, RANGE, WINDOW, TOTALYTD.

Last updated · OpenBI Studio 0.3.74