DAX - Context Flashcards

1
Q

How are DAX formulas and context related?

A

DAX computes formulas within a:
Row Context
or
Filter Context

Writing long sentence to left justify

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the default context in which a DAX expression is evaluated?

A

Row Context

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does Row Context mean?

A

It means the DAX formula is applied row by row

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In what scenario is a Row Context automatically applied?

A

When creating a calculated column
In any other scenario, you would need to create the Row Context yourself

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you create a row context within a measure?

A
  • Use an iterator.
    An iterator scans a table row by row and computes an expression during the iteration.
  • Example, SUMX
    Iterates over a table and computes an expression row by row, then aggregates its result with a SUM
  • Same Table
    All columns that you need for the iterator must be in the same table
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where might a filter context be applied?

A
  • Current visual
  • Filter pane
  • By Cross-Filtering Visuals
  • Slicers
  • In the Calculate formula
  • Any other means that filters the data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does row context affect columns in other tables that have relationships to the current table?

A

It doesn’t
Row context iterates a table. Columns in different tables are not affected by a row context.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What level does the filter context operate at?

A

The model level

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does the filter context operating at model level affect other tables?

A

Because it operates at the model level, the filter context affects:
1. The column it is filtering
2. The table the column belongs to
3. All tables that can be reached through relationships, using whatever cross-filters are set up in the model.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What level does the row context operate at?

A

The table level

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why can you not create a measure simply with a formula Sales[Quantity] * Sales[Net Price]?

A
  • Because measures do not operate on a row context, therefore when you give a calculation like this it doesn’t know what row to apply the calculation to.
  • What DOES work
    Measures function at the aggregate level. So you would need something like SUM(Sales[Quantity]) * SUM(Sales[Net Price])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you fix the measure formula Sales[Quantity] * Sales[Net Price] so it doesn’t give an error?

A

Use an aggregate
- For example, SUM( Sales[Quantity] ) is the sum of the Sales[Quantity] column for all the rows.

  • It does not require a current row, because all the rows are aggregated together.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Can an aggregate, like SUM, aggregate an expression? For example,
SUM (Sales[Quantity] * Sales[Net Price])

A

No
An aggregate can only aggregate values in a column, it cannot aggregate an expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a surprising visualization type that is not computed inside a row context?

A

A Matrix
- Each cell of a matrix is evaluated in a filter context
- If you think more about what a matrix does, aggregates values, it makes sense that even though it is displayed in rows, it is not evaluated in a row context because each of the values is an aggregate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly