I am learning DAX on the Contoso database provided for The Definitive Guide to DAX book.
I am trying to understand filter context and I wrote this measure:
CountColor:= COUNT ( 'Product'[Color] )
I put it into the pivot table where 'Product'[Color] is added to the rows section, here is the result:
Row Labels | CountColor |
---|---|
Azure | 14 |
Black | 602 |
Blue | 77 |
... | ... |
This shows that the filter context in each row is defined by the Color of that row.
When I am writing the following measure, I am anticipating that VALUES only return a unique value of the one color that is currently available in the row of the pivot table and it gets automatically converted to a scalar value:
CountColorValues:= CALCULATE (
COUNT ( 'Product'[Color] ),
FILTER ( 'Product',
'Product'[Color] = VALUES ( 'Product'[Color] )
)
)
But putting this measure to the same table, I get the error: "Calculation error in measure 'Product'[CountColorValues]: A table of multiple values was supplied where a single value was expected."
I created another measure to test if VALUES really return a single value:
CountrowsValues:= COUNTROWS (
CALCULATETABLE ( VALUES ( 'Product'[Color] )
)
)
The result:
Row Labels | CountrowsValues |
---|---|
Azure | 1 |
Black | 1 |
Blue | 1 |
... | ... |
What am I missing when I am trying to make VALUES work in FILTER?