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

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

Reply
Newbie22
Resolver I
Resolver I

Replace Value of multiple columns using Query Editor but the columns are increasing every refresh.

Hi All,

 

I have a growing file as data source. Columns are increasing every refresh in Power BI.

I need to replace all columns with "null" to 0 and it should also replace those "additional" columns aside from the existing columns.

 

I don't want to go inside Query Editor every time there's added column and then replace the value.

 

Newbie22_0-1675861167031.png

Newbie22_1-1675861350707.png

 

Is there any M code that I can use to have every columns change automatically? 

 

 

 

1 ACCEPTED SOLUTION
ams1
Responsive Resident
Responsive Resident

Hi,

 

The code in your Advanced Editor should look something like below.

 

let
Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Downloads\sampledata.xlsx"), null, true),
#"Removed Other Columns1" = Table.SelectColumns(Source,{"Data"}),
Data = #"Removed Other Columns1"{0}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Data, [PromoteAllScalars=true]),
// **********
ReplaceNulls = Table.TransformColumns(#"Promoted Headers",{},(x) => Replacer.ReplaceValue(x,null,0))
// **********
in
ReplaceNulls // don't forget about this also 🙂

 

View solution in original post

4 REPLIES 4
ams1
Responsive Resident
Responsive Resident

Hi,

 

IF your whole InputTable looks something like this (?):

ams1_4-1675865133107.png

AND you get nulls only in "values",

THEN you could replace all nulls with:

let
    Source = InputTable,
    ReplaceNulls = Table.TransformColumns(Source,{},(x) => Replacer.ReplaceValue(x,null,0))
in
    ReplaceNulls

 

Not sure what you mean ref replacing those "additional" columns, but maybe:

1) UNPIVOT (after replacing nulls)

ams1_1-1675864802376.png

2) Filter out/keep only the columns you want (?)

ams1_2-1675864870673.png

3) Pivot back

ams1_3-1675864953546.png

 

Hello @ams1 

 

Thanks for your quick reply.

 

Where do I put this code? 

let
    Source = InputTable,
    ReplaceNulls = Table.TransformColumns(Source,{},(x) => Replacer.ReplaceValue(x,null,0))
in
    ReplaceNulls

 

How do i add that in my code?

Below is my code inside Advanced Editor: 

 

let
Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Downloads\sampledata.xlsx"), null, true),
#"Removed Other Columns1" = Table.SelectColumns(Source,{"Data"}),
Data = #"Removed Other Columns1"{0}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Data, [PromoteAllScalars=true])
in
#"Promoted Headers"

ams1
Responsive Resident
Responsive Resident

Hi,

 

The code in your Advanced Editor should look something like below.

 

let
Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Downloads\sampledata.xlsx"), null, true),
#"Removed Other Columns1" = Table.SelectColumns(Source,{"Data"}),
Data = #"Removed Other Columns1"{0}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Data, [PromoteAllScalars=true]),
// **********
ReplaceNulls = Table.TransformColumns(#"Promoted Headers",{},(x) => Replacer.ReplaceValue(x,null,0))
// **********
in
ReplaceNulls // don't forget about this also 🙂

 

Thank you so much @ams1 !! It worked perfectly. You're the best 🤗

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Kudoed Authors