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

 

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!




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

 

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!




CamronBute Frequent Visitor
Frequent Visitor

Re: CALCULATE() not filtering correctly?

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

Highlighted
CamronBute Frequent Visitor
Frequent Visitor

Re: CALCULATE() not filtering correctly?

Yes, this works. Thank you!

Helpful resources

Announcements
Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

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

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

Virtual Launch Event

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 121 members 1,622 guests
Please welcome our newest community members: