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.
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!
Solved! Go to Solution.
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" ) )
)
)
Hi @tamerj1 and @Aditya_Meshram 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.
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!
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
This approach of using Coalesce() is much cleaner and easier to maintain as calculation is not repeated.
use
Count of Red colour= IF ( ISBLANK (COUNTROWS(FILTER(TABLE, TABLE[Colour]="Red"))), 0, COUNTROWS(FILTER(TABLE, TABLE[Colour]="Red")))
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
51 | |
27 | |
24 | |
14 | |
9 |
User | Count |
---|---|
75 | |
58 | |
47 | |
16 | |
12 |