cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
CamronBute Frequent Visitor
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

Accepted Solutions
tringuyenminh92 New Contributor
New Contributor

Re: CALCULATE() not filtering correctly?

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 Contributor
Super Contributor

Re: CALCULATE() not filtering correctly?

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] )
)

 

 



Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!




View solution in original post

4 REPLIES 4
tringuyenminh92 New Contributor
New Contributor

Re: CALCULATE() not filtering correctly?

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 Contributor
Super Contributor

Re: CALCULATE() not filtering correctly?

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] )
)

 

 



Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!




View solution in original post

Highlighted
CamronBute Frequent Visitor
Frequent Visitor

Re: CALCULATE() not filtering correctly?

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

CamronBute Frequent Visitor
Frequent Visitor

Re: CALCULATE() not filtering correctly?

Yes, this works. Thank you!

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 197 members 1,870 guests
Please welcome our newest community members: