FormulaCamp
Completed
10. Power Pivot and DAX · Model and Measures · 30 min

3. CALCULATE and FILTER

Lesson 3 of 8
Task 1 of 4
  1. Calculate revenue for the "Beverages" category only. Name the measure "Beverage Revenue".

Lesson theory

CALCULATE(expression, filter1, filter2…) evaluates the expression in a modified filter context. Filters are combined with AND.

  • A simple condition on one column: CALCULATE([Revenue], Products[Category] = "Beverages"). It replaces the filter on that column: in the "Pantry" row the measure will still show beverages. Filters on other columns (city, year) stay in place;
  • a condition on a calculation, or on several columns, goes through FILTER(table, condition): CALCULATE([Revenue], FILTER(Sales, Sales[Amount] >= 40)). FILTER goes through the visible rows of the table one by one;
  • you can wrap any measure in CALCULATE: CALCULATE([Transactions], Sales[Qty] >= 5).

The "Revenue" measure is already in the model.

In the trainer the model is already built: the Sales fact table on the first sheet, and the Products, Stores and Calendar lookup tables on the "Lookups" sheet. The relationships are shown in the Power Pivot panel under the sheet (expand "Data model"). The "+ Measure" button is there too: the name goes on the left, the formula on the right, and Enter saves it. Below is a PivotTable of your measures; change its rows with the "PivotTable rows" list.

The argument separator is a comma, as in English Excel (a semicolon also works if you use one throughout the formula).

Practice is part of Pro

The live spreadsheet, task checking and .xlsx files in all 170 lessons. Your progress is saved in this browser; sync across devices is coming soon.