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

Replacing Blanks with 0 - Adding +0/ creating a new measure not working!

Hello, 

 

I have been trying to replace Blank values as 0 in my matrix visualisation. I have tried using +0 in a new measure and dax functions but no luck. Below is an example of my data and what i am trying to do. Please share your ideas!!

 

DirectionCategoryDate
I117-Jun
B218-Jun
B317-Jun
I118-Jun
I220-Jun
I421-Jun
B519-Jun

EXAMPLE.PNG

I am trying to add values as "0" when the count of category for a specific date is null. 

 

Thanks in advance!

1 ACCEPTED SOLUTION

Thanks @Anonymous - that clears things up perfectly.

The simplest way to explain this is that you need related tables to make the measure work how you want, as using values from the same table as the rows and columns in the matrix doesn't quite produce the results you expect.

By using fields from two related tables, Power BI will produce the product of these two fields and resolve the measure correctly.

The only change i made to your model was to add a simple Date table, and link the date column of your example table to it, e.g.:

Separate Date table - notice that I've marked the Date column in your example table as hidden, as this links the tables and shouldn't be used in the visualSeparate Date table - notice that I've marked the Date column in your example table as hidden, as this links the tables and shouldn't be used in the visual

Now in the model, I'll swap out the matrix to use the column from this table - now your matrix works using your existing measure e.g.:

image.png

I've uploaded a copy of your doc with the change I've made - hopefully this will work so you can download and review.

Date tables are an essential modelling technique for Power BI - here's a good post on the subject for you to review.

It's also adisable to split your model into facts and dimensions if possible. The same team have a good series on this:

Hope this all helps,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

8 REPLIES 8
dm-p
Super User
Super User

Hi @Anonymous,

This is probably a better question to ask in the DAX forum - there's a lot of skilled DAX writers who don't frequent the custom visuals forum, and the DAX forum has a lot more traffic, so it's likely you'll get faster, more targeted assistance.

I can take a look though - can you provide the DAX you're using for your measure, and some information about the fields you're using? I would expect the following to work:

[Count] = COUNT([Category]) + 0

I've just tested this in a matrix where I actually want the opposite to happen, and all blanks are replaced with zeroes, as expected.

If this (or similar) is not working for you then it suggests that there may be an issue with your model or one of the fields you're adding to the matrix, so if you can provide this info then we might be able to dig a bit deeper.

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Anonymous
Not applicable

Hi @dm-p,

 

Thank you, i will also share the post under DAX Forum. 

 

I have used the following dax:

 

count = count([category]) + 0

count = if(isblank(count([category)),0,count([category]))

Child Count = 
VAR rowcount =
    COUNTROWS ( Child )
RETURN
    IF ( rowcount = BLANK (), 0, rowcount )​
count of category = IF(COUNTX(VCCdata,VCCdata[Category]) = 0, 0, COUNT(VCCdata[Category]))
ActualM =
IF (
    CALCULATE ( SUM ( Expenses[Actual] ) ) = BLANK (),
    0,
    CALCULATE ( SUM ( Expenses[Actual] ) )
)

Hi @Anonymous,

Thanks - without further knowledge of your data/model I would expect any of those to work, so I think you'll definitely get better assistance in the other forum, particualary if you can share some more info around this.

Good luck!

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Anonymous
Not applicable

hey @dm-p

 

I have used only the shown fields to create the matrix visualisation. What kind of information should i be sharing because i just tried to do the same for any sort of data i have and i was not successfull. 

 

Say i used count = count([category])+0 or  count = count([category])+1, only the fields in the table that already has value are getting updated. the fields with blank as value remain the same irrespective of my formulas. 

Hi @Anonymous - it's likely something specific to how the data model & its fields and/relationships are set up.

The simplest way to get to the crux of the problem (as someone looking in from the outside) is if you can make a copy of your .pbix file available to review. I can download and take a look and advise further.

If this is not feasible, then the next best solution is steps to replicate the data model and some sample data, and we can see if we can get an example working from here.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Anonymous
Not applicable

Hi @dm-p 

 

Please find my sample file at

https://1drv.ms/u/s!Ap-4rMiqmKwTgYJM9jHfBzG8lixDiQ?e=F8JkBo

 

 

Thanks @Anonymous - that clears things up perfectly.

The simplest way to explain this is that you need related tables to make the measure work how you want, as using values from the same table as the rows and columns in the matrix doesn't quite produce the results you expect.

By using fields from two related tables, Power BI will produce the product of these two fields and resolve the measure correctly.

The only change i made to your model was to add a simple Date table, and link the date column of your example table to it, e.g.:

Separate Date table - notice that I've marked the Date column in your example table as hidden, as this links the tables and shouldn't be used in the visualSeparate Date table - notice that I've marked the Date column in your example table as hidden, as this links the tables and shouldn't be used in the visual

Now in the model, I'll swap out the matrix to use the column from this table - now your matrix works using your existing measure e.g.:

image.png

I've uploaded a copy of your doc with the change I've made - hopefully this will work so you can download and review.

Date tables are an essential modelling technique for Power BI - here's a good post on the subject for you to review.

It's also adisable to split your model into facts and dimensions if possible. The same team have a good series on this:

Hope this all helps,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Anonymous
Not applicable

Hi @dm-p , 

 

Thank you for your solution! It worked perfectly. 

 

Also, thanks for the links to resources. 

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.