Sub topic 1
The model both objects live in
Calculated columns and measures are both DAX objects, and both belong to a data model. Where each one sits in that model explains most of their behavior. This chapter describes the model first, so later chapters can compare the two objects.
Prerequisites
This chapter assumes you can do the following:
- Move between Report, Table and Model views in Power BI Desktop.
- Read a star-schema model: tables, columns and relationships.
- Read basic DAX such as
SUM,IFand column references.
Tables, columns and relationships
A Power BI model is a set of tables joined by relationships. A table holds columns of stored data. A relationship links a column in one table to a column in another, usually a key.
In a star schema there are two kinds of table:
- A fact table records events. A
Salestable has one row per order line, with columns such asQuantityandUnit Price. - A dimension table describes things. A
Producttable has one row per product, with columns such asCategory,ColorandList Price.
Each relationship is one-to-many. One product appears in many sales rows, but each sales row points to exactly one product. That direction matters in two ways:
- Filters travel from the "one" side to the "many" side. Filtering
Product[Color]to "Red" also filtersSalesto the rows for red products. - A row on the "many" side can look up a single matching row on the "one" side. A row in
Saleshas one product, so it can read that product'sCategory.
Later chapters use these two behaviors. Filter propagation underlies measures. Single-row lookup underlies RELATED.
Where each object lives
A calculated column is part of a table. It adds a column to the table's structure, and its values are stored in the model like any imported column. A measure also belongs to a table, but only for organization. It is a stored formula and holds no values until a visual asks for a result.
Line Amount = Sales[Quantity] * Sales[Unit Price]Total Sales = SUM(Sales[Line Amount])The first formula is a calculated column on Sales. After refresh, every row has its own Line Amount value. The second formula is a measure. It has no rows of its own and is calculated each time a visual uses it.
This difference gives each object its own evaluation context. A calculated column is evaluated once per row of its table, so it works on one row at a time. This is called row context. A measure is evaluated over whichever rows the current filters leave visible. This is called filter context. The next two chapters cover them in turn.
What you see in each view
The views show the difference directly:
- In Table view, a calculated column displays values for every row. A measure shows no values.
- In Model view, both objects appear in the field list for their table. Columns show a column icon and measures show a calculator icon.
- In Report view, you can put a column on a slicer or axis. A measure can only be used as a value.
Exercise
In the star schema above, a calculated column on Sales needs the product's Category. Which relationship property makes this lookup possible, and on which table does the column live?
Show answer
Each Sales row matches exactly one Product row through the many-to-one relationship, so the column can read the single related category. The calculated column lives on the Sales table, the "many" side.