Locked lesson.
About this lesson
CALCULATE() is the super-charged SUM(anything) function, and mastering it is the secret to truly mastering Power Pivots's formula language. In this module we will show how it works, as well as how it impacts basic measure calculation.
Exercise files
Download this lesson’s related exercise files.
The CALCULATE() Function – Theory.docx66.8 KB The CALCULATE() Function – Theory - Solution.docx
66.8 KB
Quick reference
The CALCULATE() Function – Theory
An overview of CALCULATE(), the most powerful function in DAX.
When to use
When you need to create or debug a CALCULATE() function to get the correct results.
Instructions
Key concepts around measure calculation:
- Every measure result is evaluated independently
- Each measure starts with the raw and unfiltered data tables
- Determine the “Filter Context” based on the Row/Column/Filter/Slicer and Timeline selections
- Apply filter modifications from CALCULATE
- Filters defined in CALCULATE which are not in the context are ADDED
- Filters defined in CALCULATE which are in the context are OVERRIDDEN
- Filters are applied to the underlying tables based on the modified Filter Context, reducing the number of rows to use in the calculation
- The Measure’s arithmetic signature is applied to whatever rows are left
What contributes to Filter Context?
- The intersection of any fields used in the row or column fields of the PivotTable
- The application of filters in a PivotTable
- Selections in any (all) slicers and timelines linked to the PivotTable
- Filters declared in the CALCULATE() function
Examples
- Draft Beer Sales =CALCULATE([Sales],Categories[Category]="Draft Beer")
- 2009 Sales =CALCULATE([Sales],Calendar[Year]=2009)
- 2009 Draft Sales =CALCULATE([Sales],Calendar[Year]=2009,Categories[Category]="Draft Beer")
Hints & tips
- If you are trying to compare more complex operations, you may need to nest a FILTER() function in CALCULATE’s filters area
- Watch your data types:
- If your fields contain numeric data, you need to compare against a number
- If your fields contain text, you’ll need to wrap the value being compared in quotes (“)
Lesson notes are only available for subscribers.