Sub topic 6
Refresh time versus query time
This chapter assumes you can move around Power BI Desktop (Report, Table and Model views), know what a star-schema model is, and can read basic DAX such as SUM and IF. It covers one question: when does each kind of DAX object actually run, and what follows from that?
The core difference
A calculated column and a measure can both answer the same business question. They differ in when the engine evaluates them and where the result lives.
- A calculated column is evaluated at refresh time. The engine computes it once for every row, then stores the results in the model like any imported column.
- A measure is evaluated at query time. Nothing is stored. The engine runs the formula each time a visual, a slicer change, or a query asks for it.
Refresh time is when the model loads or reloads data: a scheduled refresh in the service, or a manual Refresh in Desktop. Query time is when someone interacts with a report. Opening a page, clicking a slicer, and hovering over a tooltip all trigger queries.
The diagram shows the dependency: measures read the stored columns, so a calculated column is already finished before any measure runs.
The same logic at both times
Take the line amount of each sale. Here is the calculated column version, evaluated once per row of Sales during refresh:
Line Amount = Sales[Quantity] * Sales[Unit Price]A measure then adds up the stored values for whichever rows the current filter context leaves visible:
Total Sales = SUM(Sales[Line Amount])The column does the multiplication at refresh. The measure does the addition at query time. You can also skip the column entirely:
Total Sales (no column) = SUMX(Sales, Sales[Quantity] * Sales[Unit Price])SUMX creates a row context over Sales while the query runs. It multiplies per row and sums the products. The multiplication that the column did at refresh now happens at query time, and nothing is stored.
Both versions give the same total. The cost moves from one time to the other.
Which context each one uses
The timing explains which evaluation context applies.
| Row | Calculated column | Measure |
|---|---|---|
| Evaluated | At refresh | At query time |
| Result stored in model | Yes, one value per row | No |
| Natural context | Row context: the current row | Filter context: the visible set of rows |
| Changes with slicers and filters | No, the value is fixed until the next refresh | Yes, recalculated for each query |
| Uses memory | Yes | Almost none |
A calculated column cannot respond to a slicer. When it was computed, no report existed, so there were no slicer selections. Its formula sees only the row it is calculating, plus anything reachable through relationships. A measure runs inside a query, so it sees the filters from slicers, visual axes, page and report filters, and row-level security.
This is the most useful rule of thumb in the chapter. If the answer must change when the user changes a selection, it has to be a measure.
What "stored" means in practice
A calculated column behaves like any other imported column after refresh. That has several consequences.
- It occupies memory. The engine compresses it, but a column with many distinct values compresses poorly.
- It adds to refresh duration, because the engine computes it for every row each time.
- It can be used on a slicer, a chart axis, a table column, or a filter, because it is real data in the model.
- It can be used in a relationship or as a sort-by column.
- Its value is frozen between refreshes. If the underlying data changes, the column does not update until the next refresh.
A measure has none of these properties. It is only a saved formula. It takes almost no space, and it never goes stale, because it is computed fresh from the stored columns every time.
Seeing the timing yourself
You can observe the difference in Desktop.
- In Table view, select
Salesand choose New column. EnterLine Amount = Sales[Quantity] * Sales[Unit Price]. The values appear in the grid immediately. They are computed and stored. - In Report view, choose New measure and enter
Total Sales = SUM(Sales[Line Amount]). In Table view, the measure does not appear as a column of values, because it has none. It has a value only inside a visual. - Add a card with
Total Sales, then click a slicer onProduct[Category]. The card changes. The column in Table view does not change.
You can also test the "stored" property with an edit. Change the formula of the calculated column and watch the status bar. Power BI recalculates the whole column for all rows. Edit a measure and nothing is recalculated until a visual asks for it.
Dependencies and refresh order
Calculated columns can depend on other calculated columns, including columns in other tables. The engine works out the dependency order during refresh. This has two practical effects:
- A column that depends on a
RELATEDlookup (covered in a later chapter) needs the related table loaded first. The engine handles this, but a long chain of dependent columns makes refresh slower and harder to debug. - A circular dependency between columns is an error. The engine refuses to save the formula.
Measures can reference other measures freely, because they all run at query time against stored data. A measure can reference a calculated column. A calculated column cannot reference a measure in a useful way. Doing so forces a context transition for each row, which is slow and often not what you meant.
Edge cases
DirectQuery tables
In DirectQuery mode, the data is not imported, so there is no refresh that stores column values. Calculated columns on DirectQuery tables are computed in the source query, and they are limited to expressions that can be translated to the source's SQL. Measures are still evaluated at query time, but they too are translated into source queries. The "stored at refresh" model in this chapter applies to Import mode tables.
Incremental refresh
With incremental refresh, only recent partitions are reprocessed. A calculated column's values for old partitions stay as they were last computed, unless the column's formula depends on data outside the partition. Changing the formula of a calculated column forces recomputation, which can be expensive on large historical tables.
Time-dependent logic
Suppose you write a column that uses TODAY():
Days Since Sale = DATEDIFF(Sales[Order Date], TODAY(), DAY)This value is correct only at the moment of the last refresh. A report viewed two days after a refresh still shows the old number. If you need "days since sale as of today," a measure usually serves better, because it runs at query time.
Slow measures
Because a measure runs on every query, an expensive formula costs time on every interaction. A visual with many data points and a heavy SUMX runs that formula once per point, repeatedly, as users click. Moving heavy row-level work into a calculated column can lower query time, at the price of memory and refresh time. Whether that trade is worth it is a decision for the later chapters on storage cost and choosing between the two.
Common mistakes
- Expecting a column to react to a slicer. The column has one fixed value per row. If the number must change with the selection, use a measure.
- Expecting a measure to appear in the table. A measure has no per-row values, so it cannot be dragged into a slicer or used as an axis.
- Using volatile functions in columns.
TODAY()andNOW()freeze at refresh. - Adding columns "just in case." Each one costs memory and refresh time whether or not any report uses it.
Summary of the timing model
- At refresh, the engine loads tables, then computes calculated columns row by row and stores the results.
- At query time, the engine evaluates measures in the filter context built from the report, reading the stored columns.
- Columns trade memory and refresh time for faster queries and for being usable as fields. Measures trade query time for a small model and always-current answers.
Exercise
A model has the calculated column Days Since Sale = DATEDIFF(Sales[Order Date], TODAY(), DAY). The dataset refreshes every night at 02:00. A user opens the report at 16:00 and sees the value 10 for an order placed 10 days before that morning's refresh. What value would a user see at 16:00 and why? What change would make it count days up to the moment of viewing?
Show answer
The user sees 10 at 16:00, and still sees 10 the next day until the next refresh. The column was computed at refresh time and stored, so TODAY() was evaluated once, at 02:00. To count from the moment of viewing, replace the column with a measure, because a measure runs at query time and TODAY() is evaluated for each query. Note that a measure must aggregate over the visible rows, for example Avg Days Since Sale = AVERAGEX(Sales, DATEDIFF(Sales[Order Date], TODAY(), DAY)).
Exercise
You add the measure Total Sales = SUM(Sales[Line Amount]) and place it in a card. A slicer on Product[Category] is set to "Bikes". Which part of the calculation was already done before you clicked the slicer, and which part ran after?
Show answer
The multiplication in Line Amount was done during the last refresh and is stored for every row. The SUM over the rows belonging to "Bikes" ran after the click, at query time, in the filter context created by the slicer.