Microsoft Power BI Complete Reference
上QQ阅读APP看书,第一时间看更新

Calculated measures – the basics

Calculated measures are very different than calculated columns. Calculated measures are not static, and operate within the current filter context of a report; therefore, calculated measures are dynamic and ever-changing as the filter context changes. You were introduced to filter context in the previous chapter. The concept of the filter context will be slightly expanded on later in this chapter. Calculated measures are powerful analytical tools, and because of the automatic way that measures work with filter contexts they are surprisingly simple to author.

Before you start learning about creating measures, let's first discuss the difference between implicit and explicit measures.

Implicit aggregations occur automatically on columns with numeric data types. You saw this in the previous chapter when the year column was incorrectly aggregated after being added to a report. There are some advantages to this default behavior—for example, if you simply drag the Sales Amount column into a report, the value will be automatically aggregated and you won't have to spend time creating a measure. As discussed in the next section, it's generally considered a best practice to create explicit measures in lieu of implicit measures.

An explicit measure allows a user to create a calculated measure, and there are several benefits to using explicit measures:

  • Measures can be built on each other
  • They encapsulate code, making logic changes less time-consuming
  • They centrally define number formatting, creating consistency

Calculated measures can do the following:

  • They can be assigned to any table
  • They interact with all the relationships in the data model automatically, unlike calculated columns.
  • They are not materialized in a column, and therefore cannot be validated in the Data View