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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Mederic
Post Patron
Post Patron

Exclude a particular column in the code "if is Null then_"

Hello everyone 😊,
I have a table with more than 10 columns,
I have the M code below which allows me to replace Null values with 0,
However, I would like not to apply on a particular column, in this case "ColumnName4"

How to correct the code ?

Thanks in advance

Regards

 

If_is Null then_.jpg

 

 

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ColumnName1", type text}, {"ColumnName2", Int64.Type}, {"ColumnName3", Int64.Type}, {"ColumnName4", type text}, {"ColumnName5", Int64.Type}}),
    Custom1 = Table.TransformColumns(#"Changed Type", {}, each if _ is null then 0 else _)
in
    Custom1

 

 

 

 

ColumnName1ColumnName2ColumnName3ColumnName4ColumnName5

A32 ABC65
A 87DEF 
B5576  
B7623GHI45
B  IKL98
1 ACCEPTED SOLUTION
jennratten
Super User
Super User

Hello - @jgordon11 's solution is good if you'd like to specify columns by name. Here is another option since it looks like you are trying to replace nulls with zeros for columns with numeric data.  Here is how you can do that.

= Table.ReplaceValue(#"Changed Type", null, 0, Replacer.ReplaceValue, Table.ColumnsOfType(#"Changed Type", {type nullable number}))

 

jennratten_0-1679156215024.png

 

View solution in original post

3 REPLIES 3
Mederic
Post Patron
Post Patron

Hello @jgordon11 , @jennratten ,

Thanks both for your solutions,
In my real file, both codes work perfectly,
The replacement of the Null values according to the type of the columns is in my case more appropriate
Thank you again

Regards

 

 

jennratten
Super User
Super User

Hello - @jgordon11 's solution is good if you'd like to specify columns by name. Here is another option since it looks like you are trying to replace nulls with zeros for columns with numeric data.  Here is how you can do that.

= Table.ReplaceValue(#"Changed Type", null, 0, Replacer.ReplaceValue, Table.ColumnsOfType(#"Changed Type", {type nullable number}))

 

jennratten_0-1679156215024.png

 

jgordon11
Resolver II
Resolver II

= Table.ReplaceValue(#"Changed Type", null, 0, Replacer.ReplaceValue, List.RemoveItems(Table.ColumnNames(#"Changed Type"), {"ColumnName4"}))

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.