MSBA-261 · Lesson 4 of 12 · 22 min

Calculated columns versus measures

▶ Video coming soon A video version of this lesson is on the way.

Kwabena's first draft of the model had a problem he did not notice for a week. To show net tuition, he had added a calculated column to the Registration table that subtracted discounts from gross tuition, and then a second calculated column that divided net tuition by credits to get tuition per credit. The first column was fine. The second produced a report in which the average tuition per credit for the whole college was the sum of tens of thousands of per-row ratios, a number in the millions. Signe looked at it for a moment and said, "That one should be a measure." This lesson explains the difference, and how to decide, every time, which one a calculation should be.

Three kinds of DAX calculation

DAX, Data Analysis Expressions, is the formula language of Power BI semantic models. It is used in three main places, and the PL-300 study guide asks candidates to know the use cases for each.

CalculationEvaluatedStored?ResultTypical use
Calculated columnOnce per row, at refreshYes, in the tableA new columnRow-level attributes used to filter, group or relate
MeasureAt query time, for each cell of each visualNo; only the formula is storedA single value in the current filter contextAggregations: totals, ratios, comparisons
Calculated tableOnce, at refreshYes, as a new tableA whole tableDate tables, role-playing copies, small helper tables

Calculated columns

A calculated column adds a column to a table using a DAX expression evaluated for each row. The expression sees the values in the current row, a situation called row context, so it can refer to other columns in the same row directly.

Two calculated columns on Registration. Each value is computed once per row during refresh.
Net Tuition Amount = Registration[Gross Tuition] - Registration[Discount Amount]

Credit Load Band =
SWITCH (
    TRUE (),
    Registration[Credits] >= 4, "Heavy",
    Registration[Credits] >= 2, "Standard",
    "Light"
)

Calculated columns are computed when the model refreshes and stored like any imported column. That has consequences. They take memory, they make refresh longer, and they cannot react to what a reader selects in a report, because their values were fixed at refresh time. In exchange, they can be used anywhere a normal column can: in slicers, on the rows of a matrix, in filters, as relationship keys and as sort-by columns.

A calculated column can also reach across a relationship with the RELATED function, which fetches a value from the one side of a many-to-one relationship. For example, a column on Registration could fetch the program's school from the Program table. RELATEDTABLE goes the other way, returning the rows on the many side, and is usually wrapped in a function such as COUNTROWS.

RELATED fetches a value from the one side (on Registration). RELATEDTABLE counts rows on the many side (on Program).
Program School = RELATED ( Program[School] )

Registration Count = COUNTROWS ( RELATEDTABLE ( Registration ) )

That first column is legal, but a modeler should ask whether it is needed. The School column already sits on the Program dimension, and the relationship lets any visual group Registration by school. Copying it onto the fact table duplicates data and invites authors to use the wrong one.

Measures

A measure is a DAX formula that is not evaluated until a visual asks for it. It returns one value for the current filter context: the set of filters coming from the visual's rows and columns, slicers, filter pane and any other source. The same measure, Net Tuition, returns the college total in a card, the Lakeshore total in a row of a table filtered to Lakeshore, and the October value in a line chart point for October.

Measures that aggregate first and divide second. DIVIDE returns blank instead of an error when credits are zero.
Net Tuition = SUM ( Registration[Net Tuition Amount] )

Total Credits = SUM ( Registration[Credits] )

Tuition per Credit = DIVIDE ( [Net Tuition], [Total Credits] )

Tuition per Credit shows why ratios belong in measures. The measure adds up net tuition for whatever rows are in context, adds up credits for the same rows, and divides the totals. That is the correct weighted average at every level: for one section, one campus or the whole college. Kwabena's calculated column had divided each row separately, so any total of it was meaningless, and an average of it would have weighted a one-credit lab the same as a four-credit course.

Measures take no storage beyond their definition, so adding a measure does not make the file bigger or the refresh slower. They do consume processing power when visuals are drawn, which is why the course comes back to measure performance in a later lesson.

Implicit and explicit measures

If an author drags the Credits column into a visual, Power BI aggregates it automatically according to the column's Summarize by property. That automatic aggregation is an implicit measure. An explicit measure is one you write in DAX and name. Explicit measures are better in shared models: they are named, formatted and described once, reused by every report, required by features such as calculation groups and field parameters, and they show exactly how a number is calculated. Kwabena set Summarize by to None on numeric columns where adding up made no sense, such as Program Year, and gave authors explicit measures for the columns that should be added.

Some modelers go further and enable the model setting that discourages implicit measures, so that authors must use explicit ones. When a model uses calculation groups, Power BI enforces this, because calculation groups can only modify explicit measures.

Calculated tables

A calculated table is a table defined by a DAX expression that returns a table, evaluated at refresh. The previous lesson's date table was one. Other common uses include a copy of a dimension for a second role, a small table of what-if parameter values, and a summary table for a specific purpose.

Two calculated tables: a copy of Date for a second role, and a distinct list of terms.
Registration Date = 'Date'

Term List =
DISTINCT ( SELECTCOLUMNS ( 'Date', "Term", 'Date'[Term], "Term Sequence", 'Date'[Term Sequence] ) )

Calculated tables have the same trade-off as calculated columns: they cost memory and refresh time, and they cannot respond to report filters. If a table can be produced in Power Query or in the source, that is often a better home, because Power Query transformations can be reused by dataflows and do not need DAX knowledge to maintain. DAX calculated tables are most useful when the logic depends on data already in the model, such as the range of dates in a fact table.

Deciding: column, measure or Power Query?

Kwabena wrote a short decision rule on the clinic whiteboard, and it is a good one to memorize.

A decision flowchart. Start: Does the result need to react to report filters and aggregate correctly at every level? Yes leads to Measure. No leads to: Is it a fixed attribute of each row, used to slice, filter, sort or relate? Yes leads to: Can it be computed in Power Query or the source? Yes leads to Power Query column; No leads to Calculated column. No leads to Reconsider the design.
Choosing between a measure, a calculated column and a Power Query column.
  • If the value should change with what the reader selects, or must total correctly at every level, it is a measure. Totals, counts, averages, ratios, percentages of total, comparisons with last year and rankings are all measures.
  • If the value is a fixed attribute of each row that readers will slice, filter or group by, it is a column. A credit-load band, an age group or a weekend flag are columns.
  • If it is a column, prefer to create it in Power Query or the source when you can, and use a DAX calculated column when the logic needs DAX features, such as values from related tables or the model's own data.

Microsoft summarizes the principle as "as far upstream as possible, as far downstream as necessary". Calculations shared across many models belong upstream, in the source or a dataflow. Calculations that only make sense at query time, such as ratios, belong downstream, in measures.

Quick measures

Power BI's quick measures generate common DAX patterns from a dialog: choose a calculation such as year-to-date total, running total, average per category or percentage difference, pick the base measure and fields, and Power BI writes the DAX. The PL-300 study guide lists creating a measure with quick measures as a skill. Copilot in Power BI Desktop can also suggest measures from a description, if the workspace is on a capacity that supports Copilot.

Quick measures are a good way to learn patterns, and Kwabena used one to draft a running total. But he always read the generated formula, renamed it, removed generated comments he did not need, and checked the numbers against a manual calculation, because a quick measure only knows what you choose in the dialog. A year-to-date quick measure built on the wrong date column, for example, is fast to create and wrong.

Worked problem

Column or measure?

For each requirement, decide whether Kwabena should build a measure or a column: (a) the percentage of credits taken online; (b) a flag for students aged 25 or over at the start of term; (c) full-time-equivalent students, defined as total credits divided by 15; (d) a Program Category column used as a slicer.

Show solution
  1. (a) A ratio that must total correctly by campus and program: measure.
  2. (b) A fixed attribute of each enrolment row that readers slice by: column, best computed in Power Query from birth date and term start date.
  3. (c) An aggregation that changes with filters: measure, defined as DIVIDE ( [Total Credits], 15 ).
  4. (d) A descriptive attribute of a program: a column on the Program dimension, from the source or Power Query.

Answer: (a) measure; (b) column; (c) measure; (d) column on the Program dimension.

Formatting and documenting measures

A measure's format string controls how its result appears in every visual: currency with no decimals for Net Tuition, a whole number with a thousands separator for headcount, one decimal place for Credits per Student. Setting the format on the measure means every report shows it the same way. Kwabena also filled in each measure's description, which appears as a tooltip in the Data pane and is read by Copilot, and grouped measures into display folders.

Measures can also use dynamic format strings, which choose a format with a DAX expression. For example, a measure showing revenue could display thousands as "K" and millions as "M" depending on the size of the value. Dynamic format strings change only the display, not the value, so totals and sorting still use the underlying number.

DAX query view and the model's DAX

Power BI Desktop's DAX query view lets you write DAX queries against the model and see results in a grid, which is a quick way to test a measure without building a visual. It can also show the definitions of measures and let you update them from the query. Kwabena used it to compare his new Tuition per Credit measure with a manual calculation from the finance office for three programs before publishing.

A DAX query that tests three measures by program in DAX query view.
EVALUATE
SUMMARIZECOLUMNS (
    Program[Program Name],
    "Net Tuition", [Net Tuition],
    "Credits", [Total Credits],
    "Tuition per Credit", [Tuition per Credit]
)
ORDER BY Program[Program Name]

Where calculations live in a shared model

Rupert's team agreed a simple ownership rule for the Enrolment and Revenue model, and it is worth adopting in any organization. Business definitions, such as what counts as an active registration, live in the source or in Power Query, because they should be the same in every model. Row attributes needed only by this model, such as a credit-load band, live in Power Query when possible and in DAX calculated columns otherwise. Aggregations and comparisons live in measures in the shared model, so that every report built on it uses the same definitions. And report-specific calculations, such as a difference from the previous row in one visual, may live in visual calculations on that visual.

Following the rule meant that when the registrar redefined an active registration in November, to exclude audit-only students, the change was made once in Power Query. Every measure, report and app updated on the next refresh. Before the new model, the same change had needed edits to nine separate report files, and two had been missed.

Worked problem

Moving a calculated column upstream

The model has a calculated column Age Group on Registration, computed from Student[Birth Date] with RELATED and the term start date. Refresh is slow and the column is large. How could Kwabena improve it?

Show solution
  1. The age group is a fixed attribute of each registration, so it should stay a column, not become a measure.
  2. Compute the student's age at term start in Power Query, where the student and enrolment queries are merged, and then band it.
  3. Load the band as a small text column with only a handful of distinct values, which compresses well.
  4. Remove the DAX calculated column and the dependence on birth dates in the model, which also reduces privacy exposure.

Answer: Compute the age band in Power Query and remove the DAX calculated column; the model gets smaller and no longer needs birth dates.

Common mistakes

  • MistakeCalculating a ratio in a calculated column and then summing or averaging it.

    InsteadWrite ratios as measures that aggregate the numerator and denominator first, then divide.

  • MistakeAdding calculated columns to the fact table that copy attributes from dimensions with RELATED.

    InsteadLeave attributes on the dimension; the relationship already lets visuals group by them.

  • MistakeRelying on implicit measures in a shared model.

    InsteadCreate explicit, named, formatted and described measures, and set Summarize by to None where totals make no sense.

  • MistakeTrusting a quick measure without reading it.

    InsteadRead the generated DAX, rename it, and test the results against known numbers.

Summary and key terms

  • Calculated columns are evaluated per row at refresh, stored, and usable for slicing, filtering, sorting and relationships.
  • Measures are evaluated at query time in the current filter context and take no storage.
  • Calculated tables are evaluated at refresh and are useful for date tables, role-playing copies and helper tables.
  • Ratios, totals and comparisons belong in measures; fixed row attributes belong in columns, preferably built in Power Query.
  • RELATED reads from the one side of a relationship; RELATEDTABLE returns rows on the many side.
  • Explicit measures are named, formatted, described and required by calculation groups.
  • Quick measures and Copilot can draft DAX, but every generated formula must be read and tested.
DAX
Data Analysis Expressions, the formula language of Power BI semantic models.
Calculated column
A column computed by DAX for each row during refresh and stored in the table.
Measure
A DAX formula evaluated at query time that returns one value for the current filter context.
Calculated table
A table defined by a DAX table expression and computed during refresh.
Implicit measure
An automatic aggregation Power BI creates when a column is dragged into a visual.
Quick measure
A dialog that generates common DAX measure patterns.
Dynamic format string
A DAX expression that chooses how a measure's value is displayed.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Why can a calculated column not respond to a slicer selection?

    Show answer

    Its values are computed once per row at refresh and stored; they do not depend on report filters.

  2. Write a measure for full-time-equivalent students as credits divided by 15.

    Show answer

    FTE Students = DIVIDE ( [Total Credits], 15 )

  3. Give one good use of a calculated table.

    Show answer

    A date table, a copy of a dimension for a second role, or a small helper table such as a list of terms.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz