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
tcmem
Regular Visitor

How to include Zeros in column value count

I'm trying to calculate a count of items in a column that are less than or equal to 12. For some reason, it's excluding the Zeros. How do I include the Zeros in my count? I'm also excluding blanks based on two different columns. The results would be correct if the Zeros were included in the count.

 

I'm attempting to create a new measure because I need to do a calulation using the results. Please see an example below.

 

Less than 12 or Blank = CALCULATE(count('Table1'[Field1)]),'Tabel1'[Field1)]<>BLANK(),'Table1'[Field2]<>BLANK(), 'Table1'[Field2]<=12,'Table1'[Field2]=0)

 

I'm really new to using Power BI on this level. Any suggestions are appreciated.

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@tcmem

 

Hi, you can use:

 

 

Measure =
COUNTROWS (
    FILTER ( Table1, ISBLANK ( Table1[Field2] ) = FALSE () && Table1[Field2] <= 12 )
)

 

 

Measure =
CALCULATE (
    COUNT ( Table1[Field2] ),
    FILTER ( Table1; ISBLANK ( Table1[Field2] ) = FALSE () && Table1[Field2] <= 12 )
)

 

Regards

 

Victor

Lima - Peru




Lima - Peru

View solution in original post

10 REPLIES 10
pxg08680
Resolver III
Resolver III

@tcmem

a1.PNG

Left table is the raw data with zeroes and blank values and right side table shows you count with blank values also.

 

 

 

 

Thanks for your reply! I would also like to exclude blanks from 'Table1'[Field1] as well.

Column = IF( Table1[Column1] <> BLANK () , CALCULATE( COUNT (  Table1[Column1]), Table1[Column2] <= 12 || Table1[Column2] = BLANK () ))

 

a1a.png

Unfortunately, neither suggestion worked. I created another table which pulls all fields from the original table, but excludes the rows where Field1 is BLANK. This eliminates one needed filter. However, it's still not including the Field2 = Zeros in the total count with Field2 <=12. I created this formula to count Field1 if Field 2 is NOT BLANK and is <= 12.

 

Less Than 12 or Blank  = CALCULATE(COUNT(Table1'[Field1]),'Table1'[Field2] <= 12 && 'Table1'[Field2] <> BLANK())

 

If this would include the occurrences of Field2 = 0 in the count, this would yield the results I'm trying to achieve.

 

Thanks for your help thus far!

 

 

tcmem
Regular Visitor

Here's an example of my data:

 

Field1Field2
Acct113
Acct2 
Acct31
Acct45
Acct5 
Acct63
Acct70
Acct812

 

Based on my criteria of counting Field1 where Field2 is <= 12 and NOT BLANK, the results should be a count of  5.

Hi @tcmem,

 

This will also work

 

=CALCULATE(COUNTROWS(Data),Data[Field2]<=12)-COUNTBLANK(Data[Field2])

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hello Ashish,

 

Are you able to use two different Fields in this function? I need to remove blanks in Field1 & Field2.

 

Thanks for your help!

 

Hi,

 

Subtract another COUNTBLANK() with the other field


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Vvelarde
Community Champion
Community Champion

@tcmem

 

Hi, you can use:

 

 

Measure =
COUNTROWS (
    FILTER ( Table1, ISBLANK ( Table1[Field2] ) = FALSE () && Table1[Field2] <= 12 )
)

 

 

Measure =
CALCULATE (
    COUNT ( Table1[Field2] ),
    FILTER ( Table1; ISBLANK ( Table1[Field2] ) = FALSE () && Table1[Field2] <= 12 )
)

 

Regards

 

Victor

Lima - Peru




Lima - Peru

Hello Victor,

 

I used the second suggestion and it worked perfectly. 🙂 Thank you so much for your help!

 

Measure =
CALCULATE (
    COUNT ( Table1[Field2] ),
    FILTER ( Table1, ISBLANK ( Table1[Field2] ) = FALSE () && Table1[Field2] <= 12 )
)

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.