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

Preparing for a certification exam? Ask exam experts all your questions on May 15th. Register now.

Reply
Mederic
Post Patron
Post Patron

Handling Null Values

Hello,

The article in the following link presents 2 methods for handling null values.
However, the 2nd method does not seem to give the same result as the 1st method.
How can we correct this problem?
Thanks in advance

Best regards

 

DateDescriptionCreditDebit
01/12/2024Order 12341000 
02/12/2024Materials 300
03/12/2024Order 1235750 
04/12/2024Project Tulip1000540

 

1 ACCEPTED SOLUTION

Operator precedence comes in to play

1000 ?? 0 - 540 ?? 0 is equal to 1000 ?? (0 - 540) ?? 0 which is 1000

View solution in original post

7 REPLIES 7
slorin
Super User
Super User

Hi @Mederic 

another solution

List.Sum({[Credit],-[Debit]})

Stéphane 

Hello @slorin ,
Thank you for this suggestion,
This solution would logically have its place in this article in a method 3
I have the impression that it is faster than method 2

In any case, I'm keeping it for my personal training and documentation. 

Best regards

Mederic
Post Patron
Post Patron

Hello @lbendlin 
Thank you for your reply and these clarifications,
Unfortunately, it doesn't work in my case,
I tried in the 2 versions of Excel: Microsoft Office Pro Plus 2019 and Microsoft 365.

In the article, method 1 has 2 steps : Replace and subtract
Method 2 is supposed to do this in 1 step with only Coalesce
The screenshots below, which I have copied from the article, show that the result is not the same

Best reagards

Coalesce.png

As @AlienSx mentioned you need to protect the COALESCE operator from the higher level subtraction operation with parentheses.

Operator precedence comes in to play

1000 ?? 0 - 540 ?? 0 is equal to 1000 ?? (0 - 540) ?? 0 which is 1000

Hello @AlienSx ,

Thank you for your support,
I think I've understood the logic behind the brackets,
This code now works :

= Table.AddColumn(#"Changed Type", "Custom", each ([Credit] ?? 0) - ([Debit] ?? 0), type number)


Have a nice day

Best regards

lbendlin
Super User
Super User

First off - replacing null values is not necessary in 99% of scenarios.  You can work with them just fine in your DAX calculations.

 

The Coalesce operator needs to have an actual null value to work with. By themselves the "Credit" and "Debit"  columns are initially typeless (defaulting to text) and will not show nulls.

 

lbendlin_0-1745706821946.png

 

 

 

Only after you explicitly indicate the column types will you see the nulls

 

lbendlin_1-1745706869744.png

 

And now you could apply the Coalesce transform (or any of the other transforms)

 

lbendlin_2-1745706962511.png

 

As stated earlier - most of the time this isn't necessary.

 

 

 

 

 

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors