Analyzing-and-Visualizing-Data-with-Microsoft-Power-BI

Chapter 2: Modeling and Visualizing Data

Skill 2.2 Create calculated columns, calculated tables, and measures

DAX Operators

Logical Operators:

Using DAX functions in calculated columns

@icon-info-circle See pg. 117 for a list of DAX mathematical functions.
@icon-info-circle See pg. 118 for a list of DAX datetime functions.

Using LOOKUPVALUE

Grouping values

@icon-warning Calculated columns cannot be sorted by subsequent, dependent calculated columns.

Using variables in calculated columns

@icon-warning Variables can only be accessed within the DAX EXPRESSION that they are defined in.

@icon-warning Calculated columns consume RAM.

Evaulation Context

Circular dependencies in calculated columns

Calculated tables

FILTER

VARIABLES

ALL

CALCULATETABLE

@icon-info-circle For more information on the filter arguments in CALCULATE, see “Fitler Arguments in CALCULATE” at https://www.sqlbi.com/articles/filter-arguments-in-calculate/.

VALUES and DISTINCT

SUMMARIZE and SUMMARIZECOLUMNS

ADDCOLUMNS and SELECTCOLUMNS

TOPN

CROSSJOIN, GENERATE, and GENERATEALL

GENERATESERIES

CALENDAR and CALENDERAUTO

ROW

UNION

@icon-warning If aligned columns in a UNION have differing data types, they will be combined in accordance with DAX data type coercion (e.g. type Text overrules type Whole Number).

@icon-info-circle Power Query’s APPEND combines tables vertically. It is essentially a UNION.

@icon-info-circle Recall that tables can be hidden in the DAX Data Model.

INTERSECT

EXCEPT

NATURALINNERJOIN

NATURALLEFTOUTERJOIN

DATATABLE

@icon-warning The values in the third parameter must be constants. DAX expressions are not allowed.

Using variables in calculated tables

@icon-warning Remember that variables are only evaluated once in the context in which they are defined. Because of this, they are USELESS in iterator functions like CALCULATE and CALCULATETABLE. In other words, variables are immutable after the first evaulation.

@icon-info-circle To see more information about using GENERATE/ROW instead of ADDCOLUMNS, see Using GENERATE and ROW instead of ADDCOLUMNS in DAX.

Measures

@icon-info-circle Measures aggregate columns and tables, and they always work in filter context. Consequently, by default, there is no concept of the current row in measures. You cannot create a measure in the same way that you can a calculated column, iterating row by row through a table.

Measures vs. calculated columns

@icon-warning Recall that measures cannot be placed into slicers.

Counting values in DAX