Visual calculation functions in DAX: all of them

Every DAX function made for visual calculations, RUNNINGSUM, MOVINGAVERAGE, PREVIOUS, NEXT, FIRST, LAST, RANGE, COLLAPSE, COLLAPSEALL, EXPAND, EXPANDALL, LOOKUP, LOOKUPWITHTOTALS and ISATLEVEL, with the window function each is a shortcut to, and examples.

Short answer: visual calculations have their own functions that work on the visual matrix: the rows and columns the visual shows. Moving along an axis: PREVIOUS, NEXT, FIRST, LAST, RANGE, RUNNINGSUM, MOVINGAVERAGE (shortcuts to OFFSET, INDEX and WINDOW). Moving between levels: COLLAPSE, COLLAPSEALL, EXPAND, EXPANDALL. Looking up a cell: LOOKUP, LOOKUPWITHTOTALS. Testing the level: ISATLEVEL. Most take an optional Axis (ROWS, COLUMNS, ...) and Reset.

They make the calculations people used to fight with in DAX (running totals, percent of parent, difference to previous) one short formula, on one visual.

Which functions move along an axis?

FunctionDoesExampleShortcut to
PREVIOUSthe previous row's valueProfitVSPrevious = [Profit] - PREVIOUS ( [Profit] )OFFSET ( -1 )
NEXTthe next row's valueProfitVSNext = [Profit] - NEXT ( [Profit] )OFFSET ( 1 )
FIRSTthe first row's valueProfitVSFirst = [Profit] - FIRST ( [Profit] )INDEX ( 1 )
LASTthe last row's valueProfitVSLast = [Profit] - LAST ( [Profit] )INDEX ( -1 )
RUNNINGSUMa running totalRunningSumSales = RUNNINGSUM ( [Sales Amount] )WINDOW
MOVINGAVERAGEa moving average over a windowMovingAverageSales = MOVINGAVERAGE ( [Sales Amount], 2 )WINDOW
RANGEa slice of rows around the current oneAverageSales = AVERAGEX ( RANGE ( 1 ), [Sales Amount] )WINDOW
Axis functions (Microsoft's examples)

RANGE ( step [, includeCurrent] [, axis] ... ) returns rows before (or after) the current one, for your own aggregation: SUMX ( RANGE ( 2 ), [Sales Amount] ) adds the current and the two previous rows.

Which functions move between levels?

FunctionEvaluated atExample
COLLAPSEone level up (the parent)Percent of parent = DIVIDE ( [Sales Amount], COLLAPSE ( [Sales Amount], ROWS ) )
COLLAPSEALLthe total of the axisPercent of grand total = DIVIDE ( [Sales Amount], COLLAPSEALL ( [Sales Amount], ROWS ) )
EXPANDone level down (the children)Average of children = EXPAND ( AVERAGE ( [Sales Amount] ), ROWS )
EXPANDALLthe lowest levelAverage of leaf level = EXPANDALL ( AVERAGE ( [Sales Amount] ), ROWS )
ISATLEVELTRUE if a column is present at the current levelIsFiscalYearAtLevel = ISATLEVEL ( [Fiscal Year] )
Level functions

In a matrix with Category and Product on rows, Percent of parent shows each product's share of its category and each category's share of the total.

How do LOOKUP and LOOKUPWITHTOTALS work?

They evaluate an expression at another cell of the visual matrix, named by its values:

-- sales of 2025 on every row (the current row's other filters still apply)
LookupSalesFor2025WithContext = LOOKUP ( SUM ( [Sales] ), [Year], "2025" )

-- the same, but unspecified columns are taken at total level
LookupSalesFor2025WithTotals = LOOKUPWITHTOTALS ( SUM ( [Sales] ), [Year], "2025" )

Index vs 2025 = DIVIDE ( [Sales], [LookupSalesFor2025WithContext] ) * 100

LOOKUP keeps the current row's other columns (for a matrix with Year and Quarter, it looks up 2025 in the same quarter); LOOKUPWITHTOTALS uses totals for any column you do not name.

What do Axis and Reset change?

-- across columns instead of rows (a matrix with months on columns)
Running across months = RUNNINGSUM ( [Sales Amount], COLUMNS )

-- restart at each year in a Year, Month hierarchy on rows
Running per year = RUNNINGSUM ( [Sales Amount], HIGHESTPARENT )

Axis values are ROWS, COLUMNS, ROWS COLUMNS, COLUMNS ROWS and versions with ROWPAGES and COLUMNPAGES for small multiples. Reset accepts NONE, HIGHESTPARENT, LOWESTPARENT, an integer or a field. Details in visual calculations.

What goes wrong?

  • Using them in measures. These functions work only in visual calculations (RANK, ROWNUMBER, OFFSET, INDEX and WINDOW work in both).
  • Order. They follow the visual's sort on the axis; sort by the right field.
  • Hidden levels. COLLAPSE needs a parent level on the axis; with one level it returns the total.
  • Fields not on the visual. A visual calculation can only use fields added to the visual (hide them if they should not show).

Where can you check this?

Where do you start?

In a matrix by category and product, add Percent of parent and Running sum as visual calculations. OFFSET and WINDOW are the model-level versions.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.