Module 13 · Power BI and Tableau: Dashboards People Use · Lesson 44 of 51

Measures, filter context and time comparisons

DAX measures (SUM, DIVIDE, CALCULATE, ALL, time intelligence) and Tableau calculated fields, table calculations and LOD expressions, each with the pandas code that checks the same number.

In this lesson · about 45 minutes

  • Write basic DAX measures and Tableau calculated fields
  • Explain filter context and how CALCULATE and ALL change it
  • Reproduce share-of-total and month-over-month numbers in pandas to verify a dashboard

Core measures

NeedPower BI (DAX)Tableaupandas check
Total salesSUM(Orders[total])SUM([Total])df.total.sum()
Order countDISTINCTCOUNT(Orders[order_id])COUNTD([Order Id])df.order_id.nunique()
Average order valueDIVIDE([Total Sales], [Orders])SUM([Total]) / COUNTD([Order Id])sum ÷ nunique
Share of all branchesDIVIDE([Total Sales], CALCULATE([Total Sales], ALL(Branch)))Quick table calculation: Percent of totals / s.sum()
Sales last monthCALCULATE([Total Sales], DATEADD('Date'[Date], -1, MONTH))LOOKUP(SUM([Total]), -1)s.shift(1)
Coffee sales on any visualCALCULATE([Total Sales], Product[category] = "Coffee")SUM(IF [Category] = "Coffee" THEN [Total] END)filter, then sum
Each branch's best month, fixedVariables and MAXX{ FIXED [Branch] : MAX([Monthly Sales]) }groupby().max()

Filter context in three rules

  1. Every cell, bar and card is calculated with the filters from its own position, the slicers and the page/report filters.
  2. CALCULATE changes those filters for one measure: adds, replaces or removes them.
  3. ALL(table or column) removes filters, which is how you get "of the total" denominators.

Measures vs calculated columns: a calculated column is worked out once per row and stored (like adding a pandas column); a measure is worked out on the fly for each visual. Use measures for anything you sum, average or divide.

Tableau's equivalents: calculated fields (row-level or aggregate), table calculations (computed over the table you see, like running totals and percent of total) and LOD expressions (FIXED, INCLUDE, EXCLUDE) that compute at a level you choose regardless of the view.

Checking dashboard numbers in pandas

Exercise

Category share, like ALL()

For Downtown only (a slicer), set share to a dict of category → that category's share of Downtown's total sales, rounded to 3 decimals. Then set coffee_vs_all to Downtown's Coffee sales divided by Coffee sales across all branches (what CALCULATE(…, ALL(Branch)) would give as a denominator), rounded to 3 decimals.

Code that runs before yours
import pandas as pd
import numpy as np
orders = pd.read_csv("kc_orders.csv", parse_dates=["date"])

Exercise

Month-over-month KPI cards

Build monthly: total sales per calendar month (use orders["date"].dt.month). Set mom to the list of month-over-month changes in percent, rounded to 1 decimal, for February to June (5 values). Set best_month to the month number with the highest sales.

Code that runs before yours
import pandas as pd
import numpy as np
orders = pd.read_csv("kc_orders.csv", parse_dates=["date"])

Check your understanding0 of 3 correct

Question 1

1.Which function removes filters for a denominator in DAX?

Question 2

2.Tableau's { FIXED [Branch] : SUM([Total]) } computes…

Question 3

3.Average order value should be a…

Quiz score: 0 of 3

Exercises solved: 0 of 2

Tip: answer every quiz question correctly first.

Written by Noviq Academy in its own words. Kettle & Crumb and all its data are made up for teaching; any resemblance to a real business is a coincidence. Python runs in your browser with Pyodide, so results can differ slightly from your own computer. Power BI, Tableau and other product names belong to their owners. Read-aloud uses your device's built-in voices.