PL-300 DAX Fundamentals: Measures, Filter Context, and CALCULATE
Write DAX measures that respond to filters
A revenue measure can show the correct total in a card and an unexpected number in a matrix. The difference often comes from DAX filter context. Start with a base measure, then use CALCULATE to control which filters it keeps or changes.
This lesson covers DAX calculations in the PL-300 Model the data domain (25–30% of the exam, skills measured from April 20, 2026). You will work with aggregations, iterators, statistical functions, quick measures, and calculated tables and columns.
Learning objectives
- Create explicit measures with
SUM,AVERAGE,MIN,MAX,COUNT,COUNTROWSandDISTINCTCOUNT. - Distinguish row context from filter context and explain context transition.
- Use
CALCULATEwith Boolean filters, table filters and filter-removal functions. - Use iterators (
SUMX,AVERAGEX) and basic statistical functions (MEDIAN,STDEV.S,PERCENTILE.INC,RANKX). - Use
DIVIDE, variables and quick measures appropriately. - Create calculated tables and columns with the right functions (
RELATED,ADDCOLUMNS,SUMMARIZE).
1. Measures: the basics
A measure is a DAX formula evaluated at query time in the filter context of each cell of a visual. You create it with New measure (Home or Table tools) and write Name = expression.
Total Sales = SUM ( FactSales[Amount] )
Total Quantity = SUM ( FactSales[Qty] )
Order Count = DISTINCTCOUNT ( FactSales[OrderID] )
Average Price = AVERAGE ( FactSales[UnitPrice] )
Lines = COUNTROWS ( FactSales )| Function | Returns | Notes |
|---|---|---|
SUM |
Sum of a numeric column | Only numeric columns |
AVERAGE |
Arithmetic mean of a column | Ignores blanks |
MIN, MAX |
Smallest and largest value | Work on numbers, dates and text |
COUNT |
Number of non-blank values in a column | Supports numbers, dates, and text. Use COUNTA for Boolean values. |
COUNTA |
Non-blank values of any type | |
COUNTROWS |
Number of rows in a table | Use when you want rows, regardless of which columns have blanks |
DISTINCTCOUNT |
Number of distinct values | Includes blank as one value |
DIVIDE ( a, b, [alt] ) |
Division returning blank or the alternate constant if the denominator is zero or blank | Prefer to / when the denominator can be zero |
Best practices:
- Write explicit measures rather than dragging numeric columns onto visuals (implicit measures), because implicit ones cannot be reused in other measures and are not available in some tools.
- Put measures in a dedicated table or in a table where they belong, using display folders.
- Reuse measures in other measures:
Margin % = DIVIDE ( [Profit], [Total Sales] ). - Format measures (currency, percent) with the Measure tools ribbon.

2. Row context and filter context
Understanding these two ideas is the key to DAX.
Filter context is the set of filters that apply to a calculation: slicers, visual axes, page and report filters, filters from relationships and filters added by CALCULATE. In a matrix with Category on rows and Year on columns, each cell has its own filter context (for example Category = Bikes and Year = 2025), and SUM ( FactSales[Amount] ) is evaluated inside it.
Row context is the "current row" in a table that DAX is iterating. It exists in a calculated column (each row of the table) and in iterator functions (SUMX, AVERAGEX, FILTER, ADDCOLUMNS). Row context alone does not filter the model. In the examples here, RELATED fetches a lookup value from the one side and RELATEDTABLE returns matching fact rows from the many side. Both rely on the model design. See Power BI model relationships and filter direction.
Context transition happens when CALCULATE (or a measure reference) is evaluated inside a row context: the current row is converted into equivalent filters. That is why a measure reference inside a customer row can evaluate for that customer. A bare SUM does not perform this transition. Customers with the same sales can still have equal results.
-- Calculated column on DimCustomer
Customer Sales = SUM ( FactSales[Amount] ) // same value for all rows (no context transition)
Customer Sales (correct) = CALCULATE ( SUM ( FactSales[Amount] ) ) // per customer through context transitionEvaluation order of the rule: relationships propagate filters from the one side to the many side, so the filters that identify the current customer, including its key, propagate to FactSales, and SUM on the fact respects it.
3. CALCULATE
CALCULATE is the most important DAX function:
CALCULATE ( <expression>, <filter1>, <filter2>, ... )It evaluates the expression in a modified filter context. The filters you supply either add to the existing context, replace the filters on a column, or remove filters, depending on their form.
Boolean filter arguments
Bike Sales = CALCULATE ( [Total Sales], DimProduct[Category] = "Bikes" )A Boolean filter on one column is shorthand for a table filter that returns the values of that column satisfying the condition (FILTER ( ALL ( DimProduct[Category] ), DimProduct[Category] = "Bikes" )). Important consequence: it replaces any existing filter on DimProduct[Category]. If a slicer selects "Accessories", Bike Sales still shows Bikes sales, because the CALCULATE filter overrides the slicer on that column. Other filters (Year, Region) remain.
![DAX formula bar: Footwear Sales = CALCULATE ( [Total Sales], Products[Category] = "Footwear" )](/media/certifications/data-analytics/power-bi-data-analyst/screens/05-dax-fundamentals/c01-calculate-boolean-filter.webp)

Table filter arguments with FILTER
Use FILTER for conditions that require a table expression, such as evaluating a measure per customer. Boolean filter arguments can use multiple columns from the same table, subject to DAX restrictions. The simple amount condition below can use a Boolean argument:
Large Line Sales =
CALCULATE ( [Total Sales], KEEPFILTERS ( FactSales[Amount] > 1000 ) )
Sales to High-Value Customers =
CALCULATE (
[Total Sales],
FILTER ( VALUES ( DimCustomer[CustomerID] ), [Total Sales] > 10000 )
)The first measure tests line amounts and intersects an existing filter on that column. The second iterates visible customer keys and evaluates the measure for each key. An order-total condition would require iterating order keys, not testing individual lines.
Removing and keeping filters
| Function | Effect |
|---|---|
ALL ( Table ) / ALL ( Column ) |
Removes all filters from the table or column; returns all rows or values |
ALLEXCEPT ( Table, Col1, ... ) |
Removes all filters on the table except the listed columns |
REMOVEFILTERS ( ... ) |
Clears filters in CALCULATE. It does not return a table for iteration. |
ALLSELECTED ( ... ) |
Removes filters from the visual but keeps those from slicers and outer filters (the "visible total") |
VALUES ( Column ) |
Distinct values of a column visible in the current context |
KEEPFILTERS ( ... ) |
Intersects the new filter with existing ones instead of replacing them |
All Products Sales = CALCULATE ( [Total Sales], REMOVEFILTERS ( DimProduct ) )
Share of All Products = DIVIDE ( [Total Sales], [All Products Sales] )
Share of Category =
VAR Categories = VALUES ( DimProduct[Category] )
VAR CategorySales =
CALCULATE ( [Total Sales], REMOVEFILTERS ( DimProduct ), Categories )
RETURN
DIVIDE ( [Total Sales], CategorySales )Share of All Products shows each product's percentage of the grand total, ignoring product filters but respecting Year and Region. ALLSELECTED can give a visual total, for example by removing a product row grouping while keeping the outer product selection. In the category example, capturing visible categories first preserves the category inferred from the current product. ALLEXCEPT alone may lose that category if there is no direct filter on it.
![DAX formula bar: % of All Products = DIVIDE ( [Total Sales], CALCULATE ( [Total Sales], REMOVEFILTERS ( Products ) ) )](/media/certifications/data-analytics/power-bi-data-analyst/screens/05-dax-fundamentals/c02-removefilters-share.webp)
Order of evaluation inside CALCULATE. Filter arguments are evaluated in the incoming context. CALCULATE then applies context transition where applicable and constructs the context used to evaluate the expression. Arguments are not processed as a left-to-right pipeline. Separate predicates intersect. Use || in an allowed Boolean expression or in FILTER when you need an OR condition.
CALCULATE with USERELATIONSHIP and other modifiers
CALCULATE also accepts USERELATIONSHIP (inactive relationships), CROSSFILTER (change direction for the calculation) and TREATAS (apply the values of one table as filters on columns of another). Use the same filter-context principles in DAX time intelligence and calculation groups.
![DAX formula bar: Sales by Ship Date = CALCULATE ( [Total Sales], USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] ) )](/media/certifications/data-analytics/power-bi-data-analyst/screens/05-dax-fundamentals/c05-userelationship.webp)
4. Iterators and row-by-row calculations
An iterator (suffix X) evaluates an expression for each row of a table and then aggregates:
Total Revenue = SUMX ( FactSales, FactSales[Qty] * FactSales[UnitPrice] )
Avg Order Value = AVERAGEX ( VALUES ( FactSales[OrderID] ), [Total Sales] )
Max Line Value = MAXX ( FactSales, FactSales[Qty] * FactSales[UnitPrice] )Use SUMX when the amount must be computed per row first (quantity times price). SUM ( Qty ) * SUM ( UnitPrice ) is wrong: it multiplies totals, not row values. The same logic explains AVERAGEX over VALUES ( OrderID ): average per order requires iterating the orders.
![DAX formula bar: Gross Revenue = SUMX ( Sales, Sales[Quantity] * Sales[UnitPrice] )](/media/certifications/data-analytics/power-bi-data-analyst/screens/05-dax-fundamentals/c04-sumx-iterator.webp)
Worked example 1: revenue and average order value.
Scenario. FactSales has a valid, non-blank OrderID on each line, plus Qty and UnitPrice, but no Amount column. Management wants total revenue, and the average revenue per order, in a card and a table by country.
Reasoning.
- Total revenue needs row-level multiplication:
Total Revenue = SUMX ( FactSales, FactSales[Qty] * FactSales[UnitPrice] ). - An order has several lines, so average order value is total revenue divided by the number of distinct orders:
Avg Order Value = DIVIDE ( [Total Revenue], DISTINCTCOUNT ( FactSales[OrderID] ) ). - Place both on a table with
DimCustomer[Country]. Relationship filtering applies the country to each calculation. - Check the grand-total row: revenue totals correctly; the average is revenue over all distinct orders (not the average of country averages).
Why alternatives are worse. AVERAGE ( FactSales[UnitPrice] ) gives average line price, not order value. SUM ( Qty ) * AVERAGE ( UnitPrice ) mixes grains and returns a wrong amount. A calculated column Amount = Qty * UnitPrice also works, but stores a new column on millions of rows; the iterator measure avoids that cost.
5. Basic statistical functions
| Function | Use |
|---|---|
MEDIAN ( Column ) |
Middle value; robust to outliers (typical order value) |
STDEV.S, STDEV.P |
Standard deviation of a sample or a population |
VAR.S, VAR.P |
Variance |
PERCENTILE.INC ( Column, k ) / PERCENTILE.EXC |
Value at the k-th percentile (inclusive or exclusive) |
COUNTBLANK, DISTINCTCOUNTNOBLANK |
Counting blanks, counting distinct without blank |
RANKX ( Table, Expression, [Value], [Order], [Ties] ) |
Rank of an item by an expression |
TOPN ( n, Table, Expression, [Order] ) |
Top n rows by an expression |
GEOMEAN, RAND, ABS, ROUND |
Other numeric helpers |
Median Line Amount = MEDIAN ( FactSales[Amount] )
Product Rank = RANKX ( ALL ( DimProduct[Product] ), [Total Sales] )
Top 5 Products Sales = CALCULATE ( [Total Sales], TOPN ( 5, ALL ( DimProduct[Product] ), [Total Sales] ) )The ranking example assumes one unique product label per row and no other product attributes filtering the row. ALL ( DimProduct[Product] ) removes the filter on that column and keeps other filters such as year and category. TOPN can return more than five rows when the fifth result is tied. Use a unique secondary sort key when exactly five rows are required.
6. Variables
VAR ... RETURN stores intermediate results, improves readability and avoids recomputing the same expression:
Sales vs Average Product =
VAR CurrentSales = [Total Sales]
VAR AvgSales = CALCULATE ( AVERAGEX ( VALUES ( DimProduct[Product] ), [Total Sales] ), REMOVEFILTERS ( DimProduct ) )
RETURN
DIVIDE ( CurrentSales - AvgSales, AvgSales )Variables are evaluated once, in the context where they are defined, not where they are used. This detail matters when a variable is defined outside CALCULATE and then used in it: the variable keeps its original value.


7. Quick measures
Quick measures (Home → Quick measure, or the Data pane context menu) generate DAX from a template: running total, percent difference, year-to-date total, rolling average, weighted average, star rating and more. You fill fields in a dialog, and Power BI writes a measure you can inspect and edit. They are good for getting started and for learning syntax, and the exam may ask what they do, but remember:
- They create normal measures; there is no special runtime behaviour.
- They require a suitable model (for example a date column for time-based measures).
- They can be edited like any measure and should be reviewed for correctness and naming.
- Copilot can also suggest measures and DAX from a description, but the author remains responsible for checking the result.
8. Calculated tables and columns
Calculated columns run at refresh for each row and are stored. Use RELATED to bring a value from the one side:
Line Margin = FactSales[Amount] - RELATED ( DimProduct[StandardCost] ) * FactSales[Qty]Calculated tables return a table:
Top Customers = TOPN ( 100, DimCustomer, CALCULATE ( SUM ( FactSales[Amount] ) ) )
Sales by Year =
SUMMARIZE ( FactSales, DimDate[Year], "Revenue", SUM ( FactSales[Amount] ) )
Product Lookup =
ADDCOLUMNS ( VALUES ( DimProduct[Product] ), "Sales", [Total Sales] )| Function | Purpose |
|---|---|
ADDCOLUMNS ( Table, "Name", Expression ) |
Adds columns computed per row |
SUMMARIZE |
Groups a table and optionally adds aggregations |
SELECTCOLUMNS |
Picks or renames columns |
DISTINCT, VALUES |
Unique values |
UNION, INTERSECT, EXCEPT |
Set operations on tables |
DATATABLE, { } constructor |
Small hard-coded tables (for example a what-if list) |
Reminders: calculated tables are evaluated at refresh and do not change with slicers. A what-if parameter (Modeling → New parameter) generates a calculated table and a measure for a slicer-driven scenario value.
9. Pitfalls and exam tips
- A bare
SUMin a calculated column gives the same total on every row; useRELATED,CALCULATEor an iterator as appropriate. - A Boolean filter in
CALCULATEreplaces slicer selections on that column. UseKEEPFILTERSto intersect with them. SUM ( Qty ) * SUM ( Price )is not the sum of Qty × Price; useSUMX.- Use
DIVIDEinstead of/when the denominator may be zero. - Percent-of-total measures need the right removal:
ALL ( Table )ignores slicers on that table too;ALLSELECTEDkeeps outer selections. - Use
COUNTfor supported non-blank column values,COUNTROWSfor rows, andDISTINCTCOUNTwhen repeated identifiers should count once. - Prefer measures over calculated columns for aggregates; prefer variables for readability and speed.
- Exam tip: In a visual with repeated values, inspect the active relationships and filters removed by the measure. In a calculated column with repeated totals, check for missing context transition.
- Exam tip: "respect the user's slicers but ignore the visual's grouping" →
ALLSELECTED. "Ignore all product filters" →REMOVEFILTERS ( DimProduct )orALL. - Exam tip: the exam may show a DAX formula and ask for its result; trace the filter context cell by cell.
10. Mini case study
Case. Alpine Gear sells through a FactSales table (OrderID, ProductID, CustomerID, DateKey, Qty, UnitPrice, Discount) related to DimProduct (Product, Category, StandardCost), DimCustomer (Name, Country) and DimDate. Managers ask for: (1) total net revenue after discount; (2) revenue of the Accessories category regardless of a Category slicer, next to the selected one; (3) each product's share of the revenue of its own category; (4) a table of the top 5 products by revenue; and (5) a calculated column on FactSales with gross margin per line.
Tasks. Write the DAX.
Solution.
- Net revenue per row needs row-level math:
Net Revenue = SUMX ( FactSales, FactSales[Qty] * FactSales[UnitPrice] * ( 1 - FactSales[Discount] ) ). Accessories Revenue = CALCULATE ( [Net Revenue], DimProduct[Category] = "Accessories" ). The Boolean filter overrides the Category slicer, which is the desired behaviour. A second measureSelected Revenue = [Net Revenue]follows the slicer.- Use the earlier Share of Category pattern with
[Net Revenue]. CaptureVALUES ( DimProduct[Category] )in the original context, clear the product dimension filters, and reapply the captured categories. - Top 5: On the table visual, apply a Top N filter to product based on
[Net Revenue]. If the business needs exactly five products with a deterministic tie-break, use a unique product key as a secondary ordering criterion in the ranking logic. A measure that sums the top products does not by itself filter the table to those products. Gross Margin = FactSales[Qty] * FactSales[UnitPrice] * ( 1 - FactSales[Discount] ) - FactSales[Qty] * RELATED ( DimProduct[StandardCost] )as a calculated column (row-level, usesRELATED). Alternatively compute margin as a measure withSUMXso that it uses no storage.
Commentary. Items 1 and 3 test row-level iteration and filter removal. Item 2 shows that CALCULATE overrides a slicer on the same column. Item 5 shows when a calculated column is acceptable: row-level, needs RELATED, and the model is small enough.
Key terms
- Measure: formula evaluated at query time in filter context.
- Filter context: active filters on the model for a calculation.
- Row context: the current row during iteration or in a calculated column.
- Context transition: conversion of row context to filter context by
CALCULATE. - Iterator (X function): evaluates an expression per row, then aggregates.
- ALL / ALLEXCEPT / ALLSELECTED / REMOVEFILTERS: filter-removal functions.
- KEEPFILTERS: keeps existing filters when applying a new one.
- Variable (VAR): named intermediate value evaluated once.
- Quick measure: template-generated measure.
- Calculated table: table created with DAX at refresh.
Summary checklist
- I can write SUM, COUNTROWS, DISTINCTCOUNT and DIVIDE measures.
- I can explain row context, filter context and context transition.
- I can use CALCULATE with Boolean, table and filter-removal arguments.
- I can choose SUMX instead of multiplying aggregates.
- I can use MEDIAN, STDEV.S, PERCENTILE.INC, RANKX and TOPN.
- I can use variables and review quick measures.
- I can create calculated columns with RELATED and calculated tables with SUMMARIZE or ADDCOLUMNS.
Official sources
-
Study guide for Exam PL-300: https://learn.microsoft.com/en-us/credentials/certifications/resources/study-guides/pl-300 (opens in a new tab)
-
DAX overview: https://learn.microsoft.com/en-us/dax/dax-overview (opens in a new tab)
-
CALCULATE function: https://learn.microsoft.com/en-us/dax/calculate-function-dax (opens in a new tab)
-
Context in DAX: https://learn.microsoft.com/en-us/dax/dax-glossary (opens in a new tab)
-
Use quick measures: https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-quick-measures (opens in a new tab)
-
Create calculated tables: https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-calculated-tables (opens in a new tab)
-
Microsoft Learn, COUNT, ALLSELECTED and TOPN: https://learn.microsoft.com/en-us/dax/count-function-dax (opens in a new tab), https://learn.microsoft.com/en-us/dax/allselected-function-dax (opens in a new tab), https://learn.microsoft.com/en-us/dax/topn-function-dax (opens in a new tab)
