Sub topic 6
Refresh time versus query time
This chapter assumes you know basic DAX syntax, can move between Report, Table and Model views in Power BI Desktop, and understand row context and filter context from the earlier chapters. It covers one question: when does each kind of DAX object actually run?
Two moments in the life of a model
A Power BI model goes through two different moments.
- Refresh time is when Power BI loads data from the sources into the model. Power Query steps run, tables are filled, relationships are built, and calculated columns are computed.
- Query time is when someone uses a report. Every visual, slicer selection or filter change sends a query to the model, and measures are computed to answer it.
A calculated column runs at refresh time. A measure runs at query time.
What this means for calculated columns
Take the calculated column from the earlier chapters:
Line Amount = Sales[Quantity] * Sales[Unit Price]Power BI evaluates this expression once for every row of Sales during refresh. It stores the results in the model like any imported column. When a report is opened later, the multiplication is not performed again. The values are already there.
Two consequences follow:
- The column is static between refreshes. If the source data changes, the column does not change until the next refresh.
- The column does not react to slicers or filters. Each row's value was fixed by its own row context, so the user's selections cannot change it.
What this means for measures
Now look at a measure:
Total Sales = SUM(Sales[Line Amount])Nothing is stored for this measure. Power BI keeps only the formula. When a visual needs a number, the engine works out which rows the current filter context leaves visible, and then runs the formula over them. A card with no filters computes the grand total. A bar chart with ten categories runs the formula ten times, once per bar, each with a different filter context.
The measure below produces the same total without any stored column:
Total Sales (no column) = SUMX(Sales, Sales[Quantity] * Sales[Unit Price])Here the per-row multiplication moves from refresh time to query time. SUMX creates a row context over Sales when the query runs.
Comparing the two
| Row | Calculated column | Measure |
|---|---|---|
| Computed | At refresh | At query time |
| Result stored in model | Yes, one value per row | No, only the formula |
| Context used | Row context | Filter context |
| Responds to slicers | No | Yes |
| Costs you pay | Memory and refresh time | Query time |
Common errors
- Expecting a column to react to a slicer. A calculated column such as
Line Amountnever changes when a user picks a year. If you need a value that depends on the selection, write a measure. - Expecting a measure to appear in the Table view with row values. A measure has no value per row, so it does not show up as a column of data. You see its results only inside a visual.
- Forgetting to refresh. After you edit a calculated column's formula in Desktop, Power BI recalculates it. After you change the source data, the column is out of date until the next refresh, either in Desktop or in the service.
Exercise
A report has a calculated column Line Amount and a measure Total Sales = SUM(Sales[Line Amount]). The source system corrects a unit price at noon, and no refresh happens afterward. A user opens the report at 3 pm and applies a year slicer. Which of the two objects reflects the corrected price, and which one reacts to the slicer?
Show answer
Neither reflects the corrected price. Line Amount was computed at the last refresh, and the measure sums that stored column, so both stay out of date until the next refresh. Only the measure reacts to the slicer, because it is computed at query time in the filter context. The column's values were fixed at refresh time and do not change with the slicer.