Locked lesson.
About this lesson
In this module we will create measures using the CALCULATE() function in a our model, showing how they work and add value to our business intelligence.
Exercise files
Download this lesson’s related exercise files.
The CALCULATE() Function – Application.xlsx873.5 KB The CALCULATE() Function – Application - Completed.xlsx
875.4 KB
Quick reference
The CALCULATE() Function – Application
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.