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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
PhilippeMuniesa
Resolver I
Resolver I

Table.ReplaceText or Value, in multiple columns selected by their order number

Hello,

 

I try to write a function to make a dynamic replacement in different columns of a table. The table is not always the same, and the columns are not of the same number and do not have the same name.

 

I started with an example, and I identify in a list the 4 columns in which the replacement must be apply.

 

But after, I always get stuck, I would use the list as the parameter of the function Table.ReplaceValue or Text,

 

I made this draft.

------------------------

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIGYhMgNgViMyA2B2ILILZUitWJBstiQbGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t]),

W=1,
X=2,
Y=3,
Z=7,
Liste_des_Colonne_A_Supprimer = {Table.ColumnNames(Source){W},Table.ColumnNames(Source){X},Table.ColumnNames(Source){Y},Table.ColumnNames(Source){Z}}

//Wrong
//#"Replaced Value" = Table.ReplaceValue(Source,"","0",Replacer.ReplaceValue,{Table.ColumnNames(Source){List.Count(Table.ColumnNames(Source)) - 3}})

//Wrong
// #"Replaced Value" = Table.ReplaceValue(Source,"","0",Replacer.ReplaceValue,{Table.ColumnNames(Source),List.FromText(Liste_des_Colonne_A_Supprimer)})


//Wrong
// #"Replaced Value" = Table.ReplaceValue(Source,"","0",Replacer.ReplaceValue{ Table.SelectColumns( Source,List.FromText( Liste_des_Colonne_A_Supprimer ) , null) } )

in
//#"Replaced Value"
Liste_des_Colonne_A_Supprimer

-----------------------

but I block miserably and rely on the help of a super User

 

Thanks a lot

 

Philippe Muniesa

2 ACCEPTED SOLUTIONS
AlB
Community Champion
Community Champion

Hi @PhilippeMuniesa 

I'm not sure I understand but try this:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIGYhMgNgViMyA2B2ILILZUitWJBstiQbGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t]),

W=1,
X=2,
Y=3,
Z=7,
Liste_des_Colonne_A_Supprimer = {Table.ColumnNames(Source){W},Table.ColumnNames(Source){X},Table.ColumnNames(Source){Y},Table.ColumnNames(Source){Z}},
#"Replaced Value" = Table.ReplaceValue(Source,"","0",Replacer.ReplaceValue,Liste_des_Colonne_A_Supprimer)
in
#"Replaced Value"

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

View solution in original post

Jimmy801
Community Champion
Community Champion

Hello @PhilippeMuniesa 

 

here a dynamic approach. The list NumberList contains the number of columns, where the replaces have to be applied.

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIGYhMgNgViMyA2B2ILILZUitWJBstiQbGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t]),

NumberList ={1,2,3,7},
NameOfColumnsToApply = List.Accumulate(NumberList,{}, (p,c)=> p & {Table.ColumnNames(Source){c}} ),
#"Replaced Value" = Table.ReplaceValue(Source,"","0",Replacer.ReplaceValue,NameOfColumnsToApply )
in
#"Replaced Value"

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

2 REPLIES 2
Jimmy801
Community Champion
Community Champion

Hello @PhilippeMuniesa 

 

here a dynamic approach. The list NumberList contains the number of columns, where the replaces have to be applied.

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIGYhMgNgViMyA2B2ILILZUitWJBstiQbGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t]),

NumberList ={1,2,3,7},
NameOfColumnsToApply = List.Accumulate(NumberList,{}, (p,c)=> p & {Table.ColumnNames(Source){c}} ),
#"Replaced Value" = Table.ReplaceValue(Source,"","0",Replacer.ReplaceValue,NameOfColumnsToApply )
in
#"Replaced Value"

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

AlB
Community Champion
Community Champion

Hi @PhilippeMuniesa 

I'm not sure I understand but try this:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIGYhMgNgViMyA2B2ILILZUitWJBstiQbGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t]),

W=1,
X=2,
Y=3,
Z=7,
Liste_des_Colonne_A_Supprimer = {Table.ColumnNames(Source){W},Table.ColumnNames(Source){X},Table.ColumnNames(Source){Y},Table.ColumnNames(Source){Z}},
#"Replaced Value" = Table.ReplaceValue(Source,"","0",Replacer.ReplaceValue,Liste_des_Colonne_A_Supprimer)
in
#"Replaced Value"

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.