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
dte-chris
Helper I
Helper I

COUNTROWS + FILTER and include zero values

I am trying to use a filtered row count, but it's not displaying rows resulting in zero rows counted.

 

Here is my measure formula:

device_threats = COUNTROWS(FILTER('ThreatOccurrencesInTimeframe', CONTAINS('DevicesOnline', [id], 'ThreatOccurrencesInTimeframe'[device_id])))
 
I tried adding a "+ 0" to the end like this:
device_threats = COUNTROWS(FILTER('ThreatOccurrencesInTimeframe', CONTAINS('DevicesOnline', [id], 'ThreatOccurrencesInTimeframe'[device_id]))) + 0
 
But that now causes it to ignore the FILTER statement entirely, and now it's including the count of ALL rows completely unfiltered.
 
Edit: I'll clarify a little better. With my first formula, the DevicesOnline table in the report gets filtered down just fine when I select one of its parent records, but it does not display devices with threat count zero. With my second formula, the DevicesOnline table in the report is always displaying all records at all times, even if I select a parent record it keeps showing everything, like it's now completely ignoring the relationship.
1 ACCEPTED SOLUTION

I've given up on trying to get a measure to work and decided to just count it with an M query.

View solution in original post

10 REPLIES 10
lightsquared
New Member

I found this to work:

 

CCV Count =
IF (
CALCULATE( COUNT ( 'ALT Monthly Critical Control Data'[Overdue CCV] ), 'ALT Monthly Critical Control Data'[Asset Status] = "ACTIVE",'ALT Monthly Critical Control Data'[Overdue CCV] < 0,'ALT Monthly Critical Control Data'[RMM Status] = BLANK()) = BLANK(),
0,
CALCULATE( COUNT ( 'ALT Monthly Critical Control Data'[Overdue CCV] ), 'ALT Monthly Critical Control Data'[Asset Status] = "ACTIVE",'ALT Monthly Critical Control Data'[Overdue CCV] < 0,'ALT Monthly Critical Control Data'[RMM Status] = BLANK()))
 
It essentailly performs a count on filtered data and if the value is BLANK() then replace with a 0 else peform the count on filtered data normally.
az38
Community Champion
Community Champion

Hi @dte-chris 

are you sure you want to calculate countrows in 'ThreatOccurrencesInTimeframe' table based on 'DevicesOnline' table columns values? do you have appropriate relationships?


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@az38 Sorry, maybe I should have written that better. I do have a relationship. What's happening with the +0 is when I do that, the DevicesOnline starts ignoring filtering when I click on a related parent record. With my first query, everything works except rows with zeros are not displayed, and they get filtered when I click on a parent record in the report. With my second query, my DevicesOnline table in the report displays the entire table at all times, not just the ones related to the selected parent.

kentyler
Solution Sage
Solution Sage

Do you have a relationship in your data model between ThreatOccurrencesInTimeframe and DevicesOnline ?





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


@kentyler Sorry, yes there is a one-to-many relationship from DevicesOnline to ThreatOccurrencesInTimeframe.

Greg_Deckler
Super User
Super User

Perhaps

device_threats = VAR __Count = COUNTROWS(FILTER('ThreatOccurrencesInTimeframe', CONTAINS('DevicesOnline', [id], 'ThreatOccurrencesInTimeframe'[device_id])))
RETURN
IF(ISBLANK(__Count),0,__Count)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler That didn't seem to change anything.

Try clicking on your column in Values area and choose "Show items with no data"?

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler That does not appear as an option. Also, read the edit to my OP.

I've given up on trying to get a measure to work and decided to just count it with an M query.

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.