CALCULATE

Power BI · DAX (Data Analysis Expressions)

Theory

CALCULATE evaluates an expression in a modified filter context, and it is the most important function in DAX. Its first argument is the expression, usually a measure; the remaining arguments are filters that are added to, or replace, the filters coming from the visual. A simple filter such as Sales[Region] = "North" replaces any existing filter on that column, so the result is always North's figure regardless of what the visual row says about Region, while filters on other columns, like Category, still apply.

For example, North Sales = CALCULATE([Total Sales], Sales[Region] = "North") in a table by Category returns ₹1,200 for Electronics (order 101) and ₹2,000 for Home (orders 103 and 106), next to Total Sales of ₹4,200 and ₹2,000. Filter arguments can also be modifiers such as ALL, REMOVEFILTERS, KEEPFILTERS or USERELATIONSHIP, or table expressions built with FILTER.

Why we use it

Most business measures are 'X, but for Y': sales for North, sales last year, sales ignoring the region slicer. CALCULATE is how DAX expresses all of them.

When to use it

Use CALCULATE whenever a measure needs a different filter than the visual provides. Use simple column predicates where possible; wrap them in KEEPFILTERS if you want to intersect with the existing filter instead of replacing it.

How it works

  1. Measure with CALCULATE is evaluated
  2. Start from the visual's filter context
  3. Does a filter argument target a column already filtered? Yes: Replace that column's filter. No: Add the filter alongside.
  4. Apply modifiers such as ALL or USERELATIONSHIP
  5. Evaluate the expression in the new context
  6. Return the result for the cell

Syntax

CALCULATE(<expression>[, <filter1>[, <filter2>[, …]]])
Filter forms: Table[Column] = value | Table[Column] IN {…} | FILTER(table, condition)
Modifiers: ALL, ALLEXCEPT, REMOVEFILTERS, KEEPFILTERS, USERELATIONSHIP, CROSSFILTER

Example

North Sales = 
CALCULATE(
    [Total Sales],
    Sales[Region] = "North"
)

North Electronics = CALCULATE([Total Sales], Sales[Region] = "North", Products[Category] = "Electronics")  // 1,200

// Keep the visual's Region filter and add North on top:
North Only If Selected = CALCULATE([Total Sales], KEEPFILTERS(Sales[Region] = "North"))

Key points

Power BI topics

Power BI Introduction

Getting Data

Power Query (Data Transformation)

Data Modeling

DAX (Data Analysis Expressions)

Data Visualization

Dashboards & Reports

Power BI Service

Advanced Features

Projects & Case Studies

Interview & Certification

Advanced DAX & Time Intelligence

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Power BI Dashboards & DAX

Learn data visualization and interactive dashboards step-by-step. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice DAX Online 250 business scenarios on a star schema — write a measure and compare your visual with the expected one. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Power BI  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
On screen — where to click

{{ rich.ui.title }}

{{ u.text }}
  1. {{ st.n }}{{ st.text }}
{{ rich.ui.title }}
{{ u.text }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax / Where to find it
{{ current.syntax }}
Example
{{ current.example }}
What You'll Learn — click to check off
  • {{ pt.mark }} {{ pt.text }}

Share this topic