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,
Hi Payeras_BI
Muchas gracias for your help. That’s superbe!
But my query was at first summing ‘Sales’[SalesQuantity] and filtering ‘Product’[ClassName], ‘Product’[BrandName] and ‘Product’[ProductSubCategoryKey].
I doubted that the problem comes from relation matter ( for example, relation “both” etc. ) .So in order to eliminate impact of the relation, I made the model to single table one.
Anyway I will check my previous code.
Thank you again for your continuous help!
Regards,
Hi Payeras_BI ,
I am sorry. I totally misunderstood what you said.
Even if we sum a column of another table instead of 'Product'[UnitPrice], we might not be able to get rid of this problem.
The problem might be coming from the fact that more than two filters are in one table.
The query for two table ( 1 Dimension ( Product ) + 1 Fact ( Sales ) but the same thing happens like this.
Regards,
- Payeras_BI5 years ago
Solution Sage
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,
- Usagi_Nakamura5 years ago
Helper I
Hi Payeras_BI
Thank you very much for your latest post which is really helpful to me and I am sorry for replying late.
I tried to map the cases in your post to corresponding my dax query and summarize the result.
<<In your case 1>>
In this case, One Grouping column (Class) + No filer => SUMX is OK
Corresponding dax query is
<<In your case 2>>
One grouping column ( Class ) + 1 Filter Column ( Brand ) => OK
Corresponding dax query is
<<In your case 3>>
One grouping column ( Class ) + 2 Filter Column ( Class, Brand ) => NG
Corresponding dax query is
I tried some other cases and summarizing the result as below.
Thank you Kind regards,