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
Anonymous
Not applicable

How to count the number of 0's and blanks in a column

Hi, 

I am trying to create a measure that returns the total number of 0's and blanks in a column. I have tried this DAX:

 

count_ZeroOrBlank = COUNTROWS(FILTER('table1','table1'[Quantity]="0" || table1[Quantity]=""))
 
but PowerBI returns this error when I try to use the measure in a visualization: 
 
MdxScript(Model) (11, 77) Calculation error in measure 'table1'[count_ZeroOrBlank]: DAX comparison operations do not support comparing values of type Number with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.
 
How do use VALUE or FORMAT to convert one of the values and is there a better way do create the measure? 
 
This is my first post, so let me know if there is anyway I can be more specific or post "better" questions in the future!
Thank you in advance.
1 ACCEPTED SOLUTION
rsbin
Super User
Super User

@Anonymous ,

Please try this:

Count_ZeroOrBlank = CALCULATE( COUNTROWS( table1 ),
                        FILTER( table1, table1[Quantity] = 0 || table1[Quantity] = Blank() ))

The error message I believe is due to you putting your 0 in quotes.  This is making it text.

I assume your Quantity field is numeric.

Trust this works for you.

Regards,

View solution in original post

2 REPLIES 2
DataVitalizer
Super User
Super User

Hi @Anonymous 

You can use this formula knowing that null values are also considered as 0

COUNTROWS(FILTER('Table';'Table'[Column1]=0))

Did it work ? 👌Mark it as a solution to help spreading knowledge 👉A kudos would be appreciated

rsbin
Super User
Super User

@Anonymous ,

Please try this:

Count_ZeroOrBlank = CALCULATE( COUNTROWS( table1 ),
                        FILTER( table1, table1[Quantity] = 0 || table1[Quantity] = Blank() ))

The error message I believe is due to you putting your 0 in quotes.  This is making it text.

I assume your Quantity field is numeric.

Trust this works for you.

Regards,

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.