Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
DAX Fundamentals  ›  Capstone Project

CALCULATE and Filter Context

CALCULATE Function 15 minCALCULATE evaluates an expression after changing the filter context, where a filter on a column replaces existing filters on that column and is added to filters on other columns.

CALCULATE and Filter Context

Meera wants two more numbers beside each branch: its revenue from tea alone, and its share of all revenue. Both need a total worked out under different filters from the ones the visual applies — only tea, or every branch at once. CALCULATE is the one DAX function that changes filters, and it ties this whole course together.

The rule

CALCULATE runs an expression under filters you add, replace or remove.

Filter context. Every cell in a visual is calculated under a set of filters that come from its row and column headers, the slicers and the filter pane. In a table by City, the Pune cell's filter context is City = Pune, and the filter flows downhill through the relationship to Sales.

CALCULATE ( expression, filter1, filter2, … ) works in three moves:

  1. Start from the cell's current filters.
  2. Apply each filter argument. A filter on a column replaces any existing filter on that same column, and is added alongside filters on other columns.
  3. Evaluate the expression under the result.
Tea Revenue = CALCULATE ( [Total Revenue], Products[Category] = "Tea" )

Revenue Share =
DIVIDE ( [Total Revenue], CALCULATE ( [Total Revenue], ALL ( Stores ) ) )

ALL ( Stores ) removes every filter on the Stores table, so the denominator is always the all-branch total.

City Total Revenue Tea Revenue Revenue Share
Pune 240 140 40%
Mumbai 360 320 60%
Total 600 460 100%

Pune's tea is orders 1001 and 1003 (60 + 80); Mumbai's is orders 1004 and 1006 (120 + 200).

Row context and context transition. Row context — inside a calculated column or an iterator — knows the current row but filters nothing. So a calculated column on Products written as SUMX ( Sales, Sales[Qty] * Sales[Price] ) shows 600 on every product. Wrap it in CALCULATE and the current row is turned into filters, a step called context transition; now each product shows its own revenue: Masala Chai 180, Green Tea 280, Samosa 140. Referring to a measure does the same thing, because DAX wraps every measure reference in an invisible CALCULATE.

The shortcut

For any CALCULATE cell: list the cell's filters, apply the arguments — same column replaces, other column adds — then compute.

Tea Revenue in a matrix by CategoryStep 1 of 4
  1. The Tea row

    The cell's filter is Category = Tea. The argument also sets Category = Tea, which replaces it with itself: 460.

Drills

Answer fast — trust the rule.

quick drill

In a table by City, what does Tea Revenue show for Mumbai?

quick drill

In a matrix with Category on rows, what does Tea Revenue show on the Snack row?

quick drill

What does Revenue Share show for Pune?

quick drill

What does ALL ( Stores ) do inside CALCULATE?

quick drill

A calculated column on Products is SUMX ( Sales, Sales[Qty] * Sales[Price] ), with no CALCULATE. What does it show for Samosa?

Remember

  • CALCULATE runs an expression under filters you add, replace or remove.
  • List the cell's filters; same column replaces, other column adds; then compute.
  • Traps: a CALCULATE filter overrides the visual on its column, and row context alone filters nothing.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainTea Revenue and Revenue Share

Explain how CALCULATE computes Tea Revenue and Revenue Share in a table of cities, why Tea Revenue shows 460 on the Snack row of a matrix by Category, and what context transition means.