Sub topic 2
Refresh Time versus Query Time
Assume you know Power BI Desktop navigation, star-schema relationships, and basic DAX such as SUM, IF, and column references.
Refresh time versus query time
A calculated column is evaluated during data refresh. Power BI computes its value for every row and stores the results in the model. A measure is evaluated when a visual, filter, or user interaction queries the model.
Line Amount = Sales[Quantity] * Sales[Unit Price]This calculated column stores one value per Sales row. A measure calculates a result for the current filter context:
Total Sales = SUM(Sales[Line Amount])The same result can be calculated without storing Line Amount:
Total Sales (no column) =
SUMX(Sales, Sales[Quantity] * Sales[Unit Price])SUMX evaluates the expression for each visible row at query time.
Pulling values across relationships with RELATED
A calculated column can use RELATED to read a value from the one-side table of a relationship:
Product Category = RELATED(Product[Category])This works when the current Sales row has one related Product row. The result is stored in Sales. A measure usually reads the related table through filter context instead of copying the value into every fact row.
Implicit and explicit measures
Dragging a numeric column into a visual creates an implicit measure, such as an automatic sum. An explicit measure is a named DAX object:
Red Sales =
CALCULATE([Total Sales], Product[Color] = "Red")Explicit measures are easier to reuse, test, format, and control. Prefer them for business logic.
Storage and refresh cost
Calculated columns increase model storage and require computation during refresh. The cost depends on row count and column cardinality. A column with many distinct text values may compress poorly. Measures usually use less storage because they store definitions rather than one result per row.
When you need a column
Use a calculated column when users must place the value on a slicer, axis, filter, or sort field. For example, a product price band can categorize each product:
Price Band =
IF(Product[List Price] >= 100, "High", "Standard")| Need | Typical choice |
|---|---|
| Dynamic total in the current filters | Measure |
| Category on a slicer or chart axis | Column |
Exercise
A total changes with report filters, but users also need a category on a slicer. Which objects should you create?
Show answer
Create a measure for the changing total and a calculated column for the slicer category.