Forum Discussion
Which DAX functions are correct?
- 3 years ago
Anonymous Well, no sane human being would construct that measure that way. All you need to do is MAXX(FilterSegment,[Transaction Size]). You have to read up on CALCULATE extremely closely to understand why this works: CALCULATE – DAX Guide. Some CALCULATE only DAX try hard worked overtime to get CALCULATE into that formula. It's utter nonsense. But, because CALCULATE evaluates the 'Transaction Size'[Transaction Size] within the context of FilterSegment, which is a single row table, then the DISTINCT brings back a single row table of the [Transaction Size] that happens to correspond to the context of the single row table in FilterSegment, which is whatever transaction size the sales happen to fall into. It's black box, stupidly complicated nonsense and doesn't have to be nearly that difficult or obfuscated. MSHGQM - Don't Use CALCULATE! - YouTube
Anonymous The right answer is to dispose of all of that DAX and start over.
Greg_Deckler In general, I would agree. But I am in the situation to have to pass the PL-300 Exam and as far as I understood, this has been an original question in an earlier version of that exam and I try to use these questions for preparation. Therefore, I am interested to understand which solution is correct (independent of the question if the code is best practice or not).
- Greg_Deckler3 years ago
Community Champion
Anonymous As near as I can dechiper, then it *should* be FILTER, AND, CALCULATE. I hate to say anything is correct about that DAX.
- Anonymous3 years agoNot applicable
As far as I can say, the "solution" is either FILTER, AND, ALL or FILTER, AND, CALCULATE.
Problem: If you ask me, both do not work.
Particularly, the task is to code a calculated table, this means that the measure has to give either "small", "medium" or "large".
But both answers do not do that and, moreoever, technically the arguments are not fitting, because FilterSegment is a table then and the DISTINCT function gives a column....
Maybe I should not insist to find the answer...
- Greg_Deckler3 years ago
Community Champion
Anonymous Actually, I tested this locally on a sample dataset, FILTER, AND, CALCULATE does in fact work. It only works though because the DISTINCT brings back a single row table that CALCULATE converts to a scalar value. 100%, FILTER, AND, CALCULATE works.