Section 1 Row Context versus Filter Context
Calculated columns produce an output or value based off the current row. Calculated columns work methodologically through each row.
Measures look at a group of items based on any current filters that have already been applied.
In a real world example, a calculated columns produce would be best if you are trying to calculate the total cost of each sale row.
| Item Name | Price | Quantity | Total |
|---|---|---|---|
| Book | 5.40 | 1 | |
| Pencil | 1.29 | 2 |
Total = SalesTable[Price] * SalesTables[Quantity]
This is an example of how we would use a calculated columns when we need a value for each output. You could also use categories. For example, we would make a calculated columns called “Quality” that tells us the quality of each item.
Quality =
SWITCH(
TRUE(),
SalesTable[Item] = "Book", "Low",
SalesTable[Item] = "Pens", "Low",
"High"
)
)
Now if we want the sum of all the total prices, we can use a measure:
TotalSum = SUM(SalesTable[Total])
If you have regions of the United States (East, West, South, North) you could do the following
- Create a calculated columns called that calculates the total of products sold in each region
- Create a visual that shows each region in the United States
- Create a measure that calculates the sum of the calculated columns called.
- Please the measure in the visual. All four regions will remain the same but now we get the sum of each region’s products sold.
Measures are great for
- aggregations (sum, count, max)
- you want the calculation to respond dynamically to filters and slicers
- you’re creating KPIs or metrics for dashboards
- you need the calculation to change based on the visual context
Calculated Columns are great for
- You need to perform row-by-row calculations that don’t change based on filters
- You want to use the result for grouping, filtering, or slicing
- You need the calculation to be stored permanently with the data
- You’re creating categories or classifications at the row level