Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
maneschr2022
Helper II
Helper II

Count text values and return 0 if blank

Hi everyone!

 

I´m looking for a DAX that allows me to count the total number of a specific text value in a column, but if it is none/blank I want to show 0 instead of blank.

 

I was trying to use this DAX formula:

 

Count of Red colour= COUNTROWS(FILTER(TABLE, TABLE[Colour]="Red")) +0

 

But for some reason when I add this measure as a value in a table it doesn´t load (my table already has a lot of values, not sure if that is related to that issue) when I remove the +0 it loads alright in the table, but I would like to show the 0 if there blank.

 

Is there another DAX that is better to do this? thanks!

1 ACCEPTED SOLUTION

@maneschr2022 

Please try

Count of Red colour =
IF (
    NOT ISBLANK ( COUNTROWS ( TABLE ) ),
    IF (
        ISBLANK ( COUNTROWS ( FILTER ( TABLE, TABLE[Colour] = "Red" ) ) ),
        0,
        COUNTROWS ( FILTER ( TABLE, TABLE[Colour] = "Red" ) )
    )
)

View solution in original post

6 REPLIES 6
maneschr2022
Helper II
Helper II

Hi @tamerj1 and @Anonymous both Dax work in terms of getting 0 instead of blank on my table visual, the only problem is that I get multiple rows instead of concentrated in one row, I`m using a column ID that generates the rows, but with this formula, I'm getting multiple times the same ID for 0, is there any DAX that can cover that issue as well all together?.

For the creation of my table, I'm using columns that belong to 2 different tables but they share in common the ID column.

@maneschr2022 

Please try

Count of Red colour =
IF (
    NOT ISBLANK ( COUNTROWS ( TABLE ) ),
    IF (
        ISBLANK ( COUNTROWS ( FILTER ( TABLE, TABLE[Colour] = "Red" ) ) ),
        0,
        COUNTROWS ( FILTER ( TABLE, TABLE[Colour] = "Red" ) )
    )
)

Thanks a lot! works perfect now!

Anonymous
Not applicable

Hi @maneschr2022 ,
this seems a very apt use case for the COALESCE() function. You can use it like :

 

Count of Red colour NOBLANK =
COALESCE(COUNTROWS(FILTER(TABLE, TABLE[Colour]="Red")),0)

 

 
Regards

zendu
Microsoft Employee
Microsoft Employee

This approach of using Coalesce() is much cleaner and easier to maintain as calculation is not repeated.

tamerj1
Super User
Super User

Hi @maneschr2022 

use 

Count of Red colour= IF ( ISBLANK (COUNTROWS(FILTER(TABLE, TABLE[Colour]="Red"))), 0, COUNTROWS(FILTER(TABLE, TABLE[Colour]="Red")))

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.