Reputation: 1
can anyone explain me where to find an answer for the following issue: I have two measures. First one is showing current monday and it looks like this:
Curr Monday = CALCULATE(
MAX(Arkusz1[Data]),
WEEKDAY(Arkusz1[Data], 2) = 1
)
Second measure shows the values for current Monday:
Sum for current Monday = CALCULATE(
SUM(Arkusz1[Values]),
FILTER(Arkusz1,
Arkusz1[Date] = [Curr Monday]
)
)
The issue is that line Arkusz1[Data] = [Curr Monday] in a measure Sum for current Monday shows the sum for all Mondays in the column Date. To solve this issue I had to modify measure by adding variable that is exactly the same as first measure. After changes Sum for current Monday measure shows correct values.
Measure after modification:
Sum for current Monday =
var cm = CALCULATE(
MAX(Arkusz1[Data]),
WEEKDAY(Arkusz1[Data], 2) = 1
)
RETURN
CALCULATE(
SUM(Arkusz1[Wartość]),
Arkusz1[Data] = cm
)
Thank you in advance.
I,ve tried to find the answer in the internet, but I couldn't find any answer. Maybe I'm looking with incorrect word phases.
Upvotes: 0
Views: 426
Reputation: 89386
The last important details about variables is that they represent a certain value when they are defined, and they are never computed again after. In our courses we assist with countless questions from DAX developers that do not understand why replacing an expression with a variable changes the result.
The variable is evaluated only once, but the measure expression may not be.
This
Sum for current Monday = CALCULATE(
SUM(Arkusz1[Values]),
FILTER(Arkusz1,
Arkusz1[Date] = [Curr Monday]
)
)
Will evaluate the expression Arkusz1[Date] = [Curr Monday]
for each row in the table.
Upvotes: 0