Forum Discussion
Dax query returns unexpected result
- 5 years ago
Hi Usagi_Nakamura ,
Answering to your last question:
Not that I am sure this is Auto-Exist anymore but in the example above, where you exchanged Product[UnitPrice] by Sales[UnitPrice] you were still having all the ingredients to trigger it according to this:
https://docs.microsoft.com/en-us/dax/all-function-dax
"An example where auto-exist and ALL() provide unexpected results is when filtering on two or more columns of the same table (like when using slicers), and there is a measure on that same table that uses ALL()."In your last example ProductSubcategoryKey (ALL), ClassName and BrandName (SLICERS) are still from the same table. Now, while moving ClassName and BrandName to a different table could sort out the issue, we still want to learn why this is happening.
I leave it to the experts, but hoping this is of any help, I reproduced the scenario in PBI with the simplest table possible (just two rows, only one brand/class and no duplicates) to rule out possible causes:
The measure that breaks:
SUMX = VAR CurrentKey = SELECTEDVALUE('Table'[Key]) RETURN SUMX( FILTER( ALL('Table'[Key]); 'Table'[Key]<CurrentKey ); [Sum of UnitPrice] )A measure that works:
With Calculate = VAR CurrentKey = SELECTEDVALUE('Table'[Key]) RETURN CALCULATE( [Sum of UnitPrice]; 'Table'[Key]<CurrentKey )In PBI:
- A Table visualization with only one of the columns used to slice shown:
- Ok to slice by the one not present in the visualization:
- But as soon you slice by both of them the measure with SUMX breaks:
Regards,
One thing I did for to think about this topic.
I tried several patterns of filter conditions and run the query.
Let me share the result as below.
With line #7 (= ,'Product'[BrandName] ) , all the result are natural and easy to understand.
But without line #7, I feel there are some regularities in calculations but I cannot express it in a sentence.
AA) changing to "'Product'[ProductSubcategoryKey] = CurrentSubKey"
<<Without line #7>>
<<With line #7>>
BB) changing to "'Product'[ProductSubcategoryKey] <> CurrentSubKey"
<<Without line #7>>
<<With line #7>>
CC) changing to "'Product'[ProductSubcategoryKey] = CurrentSubKey + 10"
<<Without line #7>>
<<With line #7>>
DD) changing to "'Product'[ProductSubcategoryKey] = 11"
<<Without line #7>>
<<With line #7>>
I am sorry but I am not sure that it is meaningful...
Regards,
Usagi_Nakamura Yes, that is meaningul. That's basically similar to what I was trying to express in sentence in one of my earlier posts - the filter context of the subcategorykey seems to require that brandname row context, but only in SUMX and not in CONCATENATEX. That is why I added the CurrentSubcategoryKey column to my test query, but it didn't shed much light on the situation. I've put the call out for more input, will see if we get any other brains responding here, but thanks for keeping this thread going.