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
| Need | Power BI (DAX) | Tableau | pandas check |
|---|---|---|---|
| Total sales | SUM(Orders[total]) | SUM([Total]) | df.total.sum() |
| Order count | DISTINCTCOUNT(Orders[order_id]) | COUNTD([Order Id]) | df.order_id.nunique() |
| Average order value | DIVIDE([Total Sales], [Orders]) | SUM([Total]) / COUNTD([Order Id]) | sum ÷ nunique |
| Share of all branches | DIVIDE([Total Sales], CALCULATE([Total Sales], ALL(Branch))) | Quick table calculation: Percent of total | s / s.sum() |
| Sales last month | CALCULATE([Total Sales], DATEADD('Date'[Date], -1, MONTH)) | LOOKUP(SUM([Total]), -1) | s.shift(1) |
| Coffee sales on any visual | CALCULATE([Total Sales], Product[category] = "Coffee") | SUM(IF [Category] = "Coffee" THEN [Total] END) | filter, then sum |
| Each branch's best month, fixed | Variables and MAXX | { FIXED [Branch] : MAX([Monthly Sales]) } | groupby().max() |
Filter context in three rules
- Every cell, bar and card is calculated with the filters from its own position, the slicers and the page/report filters.
CALCULATEchanges those filters for one measure: adds, replaces or removes them.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
Quiz score: 0 of 3
Exercises solved: 0 of 2
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.