Forum Discussion
Max function doesn't work
- 6 years ago
In that case use this construct.
Measure = VAR MaxTime = MAX ( Table[time] ) RETURN CALCULATE ( MAX ( Sales[Column] ), Table[time] = MaxTime, field4 = "F" )You can use multiple boolean operations in the same filter argument of CALCUALTE when the opeartion is over the same column for example the below works fine
Measure = VAR MaxTime = MAX ( Table[time] ) RETURN CALCULATE ( MAX ( Sales[Column] ), Table[time] = MaxTime && Table[time] = "F" )becuase internally Table[time] = MaxTime && Table[time = "F" expands and becomes:
FILTER ( ALL ( Table[time] ), Table[time] = MaxTime && Table[time] = "F" )But in case of multiple columns DAX engine is unable to figure out the way to create exisiting combination of Time and the other column, so in that case you can use this:
Measure = VAR MaxTime = MAX ( Table[time] ) RETURN CALCULATE ( MAX ( Sales[Column] ), FILTER ( ALL ( Table[time], Table[field4] ), Table[time] = MaxTime && Table[field4] = "F" ) )but I am assuming field4 and time are the columns of the same table, other wise separate them into 2 filters of CALCULATE as shown in the first example
AntrikshSharma Thank you for your reply,
the formula works, but now I have another problem:
if inside calculate I add another condition I have another error:
the expression contains multiple column, but only a single column can be used in a true/false expression that is used as a table filter expression,
how can I add this second condition on field 4(text)?
Measure =
VAR MaxTime =
MAX ( time )
RETURN
CALCULATE ( MAX ( Sales ), Table[time] = MaxTime && field4= "F" )In that case use this construct.
Measure =
VAR MaxTime =
MAX ( Table[time] )
RETURN
CALCULATE ( MAX ( Sales[Column] ), Table[time] = MaxTime, field4 = "F" )
You can use multiple boolean operations in the same filter argument of CALCUALTE when the opeartion is over the same column for example the below works fine
Measure =
VAR MaxTime =
MAX ( Table[time] )
RETURN
CALCULATE ( MAX ( Sales[Column] ), Table[time] = MaxTime && Table[time] = "F" )
becuase internally Table[time] = MaxTime && Table[time = "F" expands and becomes:
FILTER ( ALL ( Table[time] ), Table[time] = MaxTime && Table[time] = "F" )
But in case of multiple columns DAX engine is unable to figure out the way to create exisiting combination of Time and the other column, so in that case you can use this:
Measure =
VAR MaxTime =
MAX ( Table[time] )
RETURN
CALCULATE (
MAX ( Sales[Column] ),
FILTER (
ALL ( Table[time], Table[field4] ),
Table[time] = MaxTime
&& Table[field4] = "F"
)
)
but I am assuming field4 and time are the columns of the same table, other wise separate them into 2 filters of CALCULATE as shown in the first example