Row context

In addition to filter context, several DAX functions such as FILTER() and SUMX() are iterators and execute their expressions per row of a given table. The set of rows to evaluate from this table is always defined by the filter context which was described earlier in this chapter. The expression parameter of iterating functions can aggregate the rows of a table or can invoke the filter context of the specific row being iterated via the CALCULATE() function or a measure reference.

Calculated DAX columns are used to illustrate row context. In the following screenshot, four calculated columns have been added to a Date table and reference the Weekday Sort column:

The row context in calculated columns

All four calculated columns simply add the value 1 to the Weekday Sort column, but achieve their results via distinct expressions:

Weekday Sort Plus 1 (SUM) = SUM('Date'[Weekday Sort]) + 1 
Weekday Sort Plus 1 CALC = CALCULATE(SUM('Date'[Weekday Sort])) + 1
Weekday Sort Plus 1 Measure = [Weekday Sort Summed] + 1
Weekday Sort Plus 1 = 'Date'[Weekday Sort]+1

The Weekday Sort Plus 1 CALC column and the Weekday Sort Plus 1 Measure column represent the concept of context transition. These two columns invoke the filter context (context transition) of the given row via the CALCULATE() function or implicitly via the reference of an existing measure, respectively:

  • Weekday Sort Plus 1 (SUM) computes the sum of the Weekday Sort column plus one and repeats this value for each row
  • Weekday Sort Plus 1 CALC embeds a SUM() function within the CALCULATE() function prior to adding one
  • Weekday Sort Plus 1 Measure references an existing measure which sums the Weekday Sort column and then adds one
  • Weekday Sort Plus 1 references the Weekday Sort column of the Date table and adds one

The Weekday Sort Plus 1 (SUM) expression demonstrates that aggregation functions, in the absence of CALCULATE() or the implicit CALCULATE() when invoking measures, ignore row context. The three other columns all operate on a per-row basis (row context) but achieve their results via three different methods. The Weekday Sort Plus 1 column represents the default behavior of expressions executing in a row context such as calculated columns, FILTER(), and other iterating DAX functions.

To develop more complex DAX measures, it can be necessary to ignore the row context of the input table, such as the Weekday Sort Plus 1 SUM() example or explicitly invoke the row context of the table. 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.176.145