Forum Discussion
CALCULATE() not filtering correctly?
Consider the following query result (in the Edit Queries screen):
Now here are two measures I have made on that query:
This is the result:
I expected to see:
Am I missing something, or is this a bug?
Hi Anonymous,
To use these method or multiple conditions in filtering, please wrap them in Filter method
CALCULATE([Total Views],FILTER(Views,NOT(ISBLANK(Views[Who]))))
Hi Anonymous
Two reasons I believe are contributing to your unexpected results:
- The empty values in the Who column are empty strings rather than null values (empty strings and nulls look the same in Data view, but are distinguishable in the Query Editor).
- CALCULATE filter arguments overwrite the filter context (by default) rather than intersecting with it.
Assuming the blank names are empty strings, this code should work:
Total authenticated views = CALCULATE ( [Total Views], Views[Who] <> "", VALUES ( Views[Who] ) )
4 Replies
- tringuyenminh92Memorable Member
Hi Anonymous,
To use these method or multiple conditions in filtering, please wrap them in Filter method
CALCULATE([Total Views],FILTER(Views,NOT(ISBLANK(Views[Who]))))
- AnonymousNot applicable
Yes, this works. Thank you!
- OwenAugerSuper User
Hi Anonymous
Two reasons I believe are contributing to your unexpected results:
- The empty values in the Who column are empty strings rather than null values (empty strings and nulls look the same in Data view, but are distinguishable in the Query Editor).
- CALCULATE filter arguments overwrite the filter context (by default) rather than intersecting with it.
Assuming the blank names are empty strings, this code should work:
Total authenticated views = CALCULATE ( [Total Views], Views[Who] <> "", VALUES ( Views[Who] ) )- AnonymousNot applicable
Yes, I see now. Thank you for explaining the behaviour I was missing, too.