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

Ignore if total count is zero

Hi Power BI Experts,

 

I want to be able to ignore a measure from showing in a barchart if the total count is zero. I'm currently filtering it by the value "A":

 

aCount = CALCULATE ( COUNTROWS('<tablename>'), '<tablename>'[column] = "A").

 

How can I fix this function to achieve that?

 

Thank you in advance,

Abhilash

1 ACCEPTED SOLUTION

It's really weird as a solution... but you can do something like this:

 

M1 = 
IF ( 
    [M1] = 0, 
    IF ( 
        [M2] = 0,
        [M3],
        [M3]
    ),
    [M1]
)

 

In this way, [M1] (your first measure) returns the value of M1, M2 or M3, the first non blank.

Then you repeat a similar logic in the other measures, taking into account that M2 might have been shown in M1, if M1 was blank... thus it ends up in a set of somewhat complex conditions that draw the chart in the right place.

 

Nevertheless, even if you could draw the bars one beside the other, at the end the colors will not match because the value of M1 might be M1, M2 or M3, from the DAX point of view, but from the Power BI visual one, it will always be a blue line.

 

Thus, my guess is that your only option is to write a custom visual to obrain such a behavior, even if you could solve it in DAX, it would be a dead end, because Power BI prevents you from using it as a good solution.

 

Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

 

Alberto Ferrari - SQLBI

View solution in original post

4 REPLIES 4
malagari
Responsive Resident
Responsive Resident

You can store the aCount as a DAX variable, and then return BLANK() if it is equal to zero.  Like so:

 

 

aCount = 

var aCountValue = CALCULATE( COUNTROWS(Table), Table[Column] = "A" )

return
IF( aCountValue = 0, BLANK(), aCountValue )
Dan Malagari
Consultant at Headspring

Thank you for the recommedation malagari. But, this doesn't solve the problem I have.

 

image.png

 

In this chart, I'm using 3 measures. I wanted to able to line the blue and red bars side-by-side in the absence of a value for the green bar.

Hi,

 

Share the link from where i can download your file.


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

It's really weird as a solution... but you can do something like this:

 

M1 = 
IF ( 
    [M1] = 0, 
    IF ( 
        [M2] = 0,
        [M3],
        [M3]
    ),
    [M1]
)

 

In this way, [M1] (your first measure) returns the value of M1, M2 or M3, the first non blank.

Then you repeat a similar logic in the other measures, taking into account that M2 might have been shown in M1, if M1 was blank... thus it ends up in a set of somewhat complex conditions that draw the chart in the right place.

 

Nevertheless, even if you could draw the bars one beside the other, at the end the colors will not match because the value of M1 might be M1, M2 or M3, from the DAX point of view, but from the Power BI visual one, it will always be a blue line.

 

Thus, my guess is that your only option is to write a custom visual to obrain such a behavior, even if you could solve it in DAX, it would be a dead end, because Power BI prevents you from using it as a good solution.

 

Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

 

Alberto Ferrari - SQLBI

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.