Forum Discussion
Help understanding the function VALUES when passed as a filter parameter in Calculation in Dax
- 4 years ago
Hi,
When you write
CALCULATE( [Sum revenue], 'Product'[ProductID]>10 )DAX actually goes away and does this:
CALCULATE( [Sum revenue], FILTER( ALL('Product'[ProductID]), 'Product'[ProductId] > 10 ) )eg it removes any existing filters on product id (eg the ones coming from the matrix rows and then it adds a new filter to just get ids greater than 10.
In the measure that is working it does the same but VALUES('Product'[ProductId]) add back the existing Product Ids that were in the filter context to start with.
Hi,
When you write
CALCULATE(
[Sum revenue],
'Product'[ProductID]>10
)
DAX actually goes away and does this:
CALCULATE(
[Sum revenue],
FILTER(
ALL('Product'[ProductID]),
'Product'[ProductId] > 10
)
)eg it removes any existing filters on product id (eg the ones coming from the matrix rows and then it adds a new filter to just get ids greater than 10.
In the measure that is working it does the same but VALUES('Product'[ProductId]) add back the existing Product Ids that were in the filter context to start with.
bcdobbs is correct. VALUES is restoring the local ProductId filter context that CALCULATE replaces.
I just wanted to suggest using KEEPFILTERS in your measure like this rather than VALUES:
CALCULATE (
Sales[Sum revenue],
KEEPFILTERS ( 'Product'[ProductID] > 10 )
)