Model the data · Topic 3 of 6

Measures, Quick Measures and CALCULATE

PL-300 DAX measures: write single aggregation measures, understand filter context, use CALCULATE with filters and ALL, and build quick measures.

  • 4 min
In a nutshell
  • Measures respond to filter context. Calculated columns do not.
  • CALCULATE changes filter context. A Boolean filter replaces the filter on that column.
  • ALL and REMOVEFILTERS remove filters. ALLSELECTED keeps slicer and outer filters.

What it is

A measure is a DAX formula that calculates a result when a visual asks for it. The result depends on the filter context: which slicers, rows and columns are active. CALCULATE is the key function, because it changes the filter context before it evaluates an expression. Quick measures generate common measures for you.

Visual filtersslicers, rows, columnsFilter contextrows still visibleCALCULATEadds or changes filtersResultone value per cell

How it works

Single aggregation measures

Explicit measures are created with New measure and a name. The aggregation functions are:

FunctionResult
SUMTotal of a numeric column
AVERAGEMean of a column
MIN, MAXSmallest or largest value
COUNTNumber of non blank values
COUNTROWSNumber of rows in a table
DISTINCTCOUNTNumber of different values
DIVIDEDivision that returns blank (or a chosen value) when the divisor is zero
Total Sales = SUM ( Sales[Amount] )
Order Count = DISTINCTCOUNT ( Sales[OrderID] )
Average Price = DIVIDE ( [Total Sales], SUM ( Sales[Quantity] ) )

Prefer DIVIDE to the / operator, because it handles division by zero. An implicit measure is a column dragged into a visual with an aggregation. An explicit measure is one you write. Explicit measures are reusable, can be formatted once and are required by calculation groups.

Iterator functions

Functions ending in X, such as SUMX and AVERAGEX, evaluate an expression row by row and then aggregate. Use them when the value needs row level math.

Revenue = SUMX ( Sales, Sales[Quantity] * Sales[UnitPrice] )

A simple SUM cannot multiply two columns row by row.

Row context and filter context

  • Row context exists when DAX visits one row at a time, as in a calculated column or inside an iterator.
  • Filter context is the set of filters that apply to a calculation. A matrix cell showing Bikes in 2024 has a filter context of Category = Bikes and Year = 2024.

A measure in a matrix is evaluated once for every cell, each with its own filter context.

CALCULATE

CALCULATE evaluates an expression in a modified filter context.

Red Sales = CALCULATE ( [Total Sales], Product[Color] = "Red" )
Sales All Products = CALCULATE ( [Total Sales], ALL ( Product ) )
Share of Total = DIVIDE ( [Total Sales], CALCULATE ( [Total Sales], ALL ( Product ) ) )

Key points:

  • A Boolean filter such as Product[Color] = "Red" replaces any existing filter on that column.
  • ALL removes filters from a table or columns. REMOVEFILTERS is a clearer name for the same use inside CALCULATE.
  • ALLSELECTED removes filters but keeps those from slicers and outer visuals, which is useful for a percentage of the visible total.
  • KEEPFILTERS adds a filter instead of replacing the existing one.
  • FILTER returns a table of rows that meet a condition, for example when the condition compares two measures. A simple Boolean filter is faster.

Variables

VAR stores a value once, which makes formulas easier to read and often faster.

Sales vs Target % =
VAR Actual = [Total Sales]
VAR Target = [Sales Target]
RETURN DIVIDE ( Actual - Target, Target )

Quick measures

A quick measure is created from New quick measure and chosen from a list. You select the calculation, drag fields to the boxes, and Power BI writes the DAX. You can read and edit it afterwards. The categories include aggregate per category, filters, time intelligence, totals (such as running total), mathematical operations and text. Examples are Average per category, Running total, Year over year change and Percent difference from filtered value. Quick measures are a good way to learn DAX patterns, and the result is an ordinary explicit measure.

A worked scenario

A manager wants a card showing the share of sales that comes from the selected category compared with all categories. The analyst writes DIVIDE ( [Total Sales], CALCULATE ( [Total Sales], ALL ( Product[Category] ) ) ). When the card is placed in a visual filtered by a category slicer, the numerator is that category and the denominator ignores the filter. She uses DIVIDE so the card shows blank, not an error, when nothing is selected.

What to remember for the exam

  • Measures respond to filter context. Calculated columns do not.
  • CALCULATE changes filter context. A Boolean filter replaces the filter on that column.
  • ALL and REMOVEFILTERS remove filters. ALLSELECTED keeps slicer and outer filters.
  • Iterators such as SUMX evaluate row by row.
  • Quick measures write ordinary measures that you can edit. DIVIDE avoids division by zero.
Exam tip

For "percent of total", the denominator is CALCULATE with ALL, and the numerator is the plain measure.

How the exam asks about this

  • "A measure must ignore a slicer on Category." CALCULATE with ALL or REMOVEFILTERS on Category.
  • "Multiply price by quantity for each row, then add." SUMX.
  • "Return blank instead of an error for zero." DIVIDE.
  • "Create a running total without writing DAX." A quick measure.

Common mistakes

Using SUM on a product of two columns. It needs an iterator.

Expecting a Boolean filter to add to an existing filter. It replaces it.

Forgetting that filter context differs per visual cell.

Writing a calculated column when a measure is needed.

Check yourself

  • What does CALCULATE do?

    It evaluates an expression in a modified filter context.

  • Which function divides safely?

    DIVIDE.

  • Which function removes all filters from a table?

    ALL, or REMOVEFILTERS inside CALCULATE.

Topic 3 of 6 in Model the data

Test yourself on Model the data

The full Microsoft PL-300 question bank has 657 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Microsoft. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.