Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
CamronBute
Frequent Visitor

CALCULATE() not filtering correctly?

Consider the following query result (in the Edit Queries screen):

image.png

 

Now here are two measures I have made on that query:

image.pngimage.png

 

This is the result:

image.png

 

I expected to see:

image.png

 

 

Am I missing something, or is this a bug?

2 ACCEPTED SOLUTIONS
tringuyenminh92
Memorable Member
Memorable Member

Hi @CamronBute,

 

To use these method or multiple conditions in filtering, please wrap them in Filter method

 

CALCULATE([Total Views],FILTER(Views,NOT(ISBLANK(Views[Who]))))

Capture.PNG

 

View solution in original post

OwenAuger
Super User
Super User

Hi @CamronBute

 

Two reasons I believe are contributing to your unexpected results:

  1. 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).
  2. 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] )
)

 

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

4 REPLIES 4
OwenAuger
Super User
Super User

Hi @CamronBute

 

Two reasons I believe are contributing to your unexpected results:

  1. 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).
  2. 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] )
)

 

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Yes, I see now. Thank you for explaining the behaviour I was missing, too.

tringuyenminh92
Memorable Member
Memorable Member

Hi @CamronBute,

 

To use these method or multiple conditions in filtering, please wrap them in Filter method

 

CALCULATE([Total Views],FILTER(Views,NOT(ISBLANK(Views[Who]))))

Capture.PNG

 

Yes, this works. Thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.