Forum Discussion
replace values for all existing and new columns
Is there any way to replace values for all columns i.e existing and new columns dynamically instead of hard coding the column names
as example if today the source data has 4 columns and the next day if there are 5 columns how to replace values in the col4 values as well as the replace query step wont have col4 in the code.
ID col1 col2 col3
ID col1 col2 col3 col4
Hi,
Since you have not shared any specific details, here is a generic answer. These 2 lines of M code will replace null with 0 in all columns (including additional columns after refreshing)
GetColumnNames = Table.ColumnNames(#"Promoted Headers"), #"Replaced Value01" = Table.ReplaceValue(#"Promoted Headers",null,0,Replacer.ReplaceValue,GetColumnNames)Hope this helps.
2 Replies
- foodd
Community Champion
Hello kb177 , remember to adhere to the decorum of the Community Forum when asking a question.
Please provide your work-in-progress Power BI Desktop file (with sensitive information removed) that covers your issue or question completely in a usable format (not as a screenshot).
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Please show the expected outcome based on the sample data you provided.
https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523/highlight/true#M607150
This allows members of the Forum to assess the state of the model, report layer, relationships, and any DAX applied. - Ashish_Mathur
Super User
Hi,
Since you have not shared any specific details, here is a generic answer. These 2 lines of M code will replace null with 0 in all columns (including additional columns after refreshing)
GetColumnNames = Table.ColumnNames(#"Promoted Headers"), #"Replaced Value01" = Table.ReplaceValue(#"Promoted Headers",null,0,Replacer.ReplaceValue,GetColumnNames)Hope this helps.