Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi.
I have a DAX measure, which looks for the maximum date in a DateColumn:
I want to count the number of rows where the [CVSS v3]score is 9 or above AND the [ExtractDate] equals the measure [Defender - Current Month].
Solved! Go to Solution.
Hi @marktait
The reason for this behaviour is that when a measure is evaluated in a row context, that row context is first converted into an equivalent filter context.
This is known as context transition (see this article).
In your example, [Defender - Current Month] is being evaluated in the row context of Defender created by FILTER (an iterator).
For each row where it is evaluated
To fix this, you can use a couple of methods:
1. Evaluate [Defender - Current Month] in a variable outside FILTER:
CVSS 9-10 current month fix v1 =
VAR CurrentMonth = [Defender - Current Month]
RETURN
COUNTROWS (
FILTER (
Defender,
Defender[CvSS v3] >= 9 && Defender[ExtractDate] = CurrentMonth
)
)
2. Use LASTDATE to make the measure more concise (my preferred method):
CVSS 9-10 current month fix v2 =
CALCULATE (
COUNTROWS ( Defender ),
LASTDATE ( Defender[ExtractDate] ),
Defender[CvSS v3] >= 9
)
A general principle is that it is better to filter specific columns rather than tables, which is another reason I would prefer the 2nd version.
Does this work for you?
Regards
Hi Owen.
Both of those worked for me.
Thank you very much for going to the effort of explaining why they work too - I really appreciate that.
All the best, Mark
Hi @marktait
The reason for this behaviour is that when a measure is evaluated in a row context, that row context is first converted into an equivalent filter context.
This is known as context transition (see this article).
In your example, [Defender - Current Month] is being evaluated in the row context of Defender created by FILTER (an iterator).
For each row where it is evaluated
To fix this, you can use a couple of methods:
1. Evaluate [Defender - Current Month] in a variable outside FILTER:
CVSS 9-10 current month fix v1 =
VAR CurrentMonth = [Defender - Current Month]
RETURN
COUNTROWS (
FILTER (
Defender,
Defender[CvSS v3] >= 9 && Defender[ExtractDate] = CurrentMonth
)
)
2. Use LASTDATE to make the measure more concise (my preferred method):
CVSS 9-10 current month fix v2 =
CALCULATE (
COUNTROWS ( Defender ),
LASTDATE ( Defender[ExtractDate] ),
Defender[CvSS v3] >= 9
)
A general principle is that it is better to filter specific columns rather than tables, which is another reason I would prefer the 2nd version.
Does this work for you?
Regards
User | Count |
---|---|
93 | |
85 | |
76 | |
66 | |
62 |
User | Count |
---|---|
110 | |
96 | |
95 | |
64 | |
57 |