Forum Discussion
Michael_HERE
2 years agoRegular Visitor
How to replace a value in multiple columns when the columns have to be dynamically selected?
I need to replace a value in a set of columns (in this case null value with 0), but I cannot hard-code the columns. Instead, I need to determine the columns dynamically: only columns with a specific ...
- 2 years ago
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], FilteredList = List.Buffer(List.Select(Table.ColumnNames(Source), each Text.StartsWith( _ , "Invoiced_"))), #"Replaced Value" = Table.ReplaceValue(Source,null,0,Replacer.ReplaceValue, FilteredList) in #"Replaced Value"
Vijay_A_Verma
2 years agoMost Valuable Professional
Use this
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
FilteredList = List.Select(Table.ColumnNames(Table1), each Text.StartsWith( _ , "Invoiced_")),
#"Replaced Value" = Table.FromRecords(
Table.TransformRows(Source, (r) => List.Accumulate(FilteredList, r, (s,c)=>
Record.TransformFields(s,{{c, each if _ = null then 0 else _}})))
, Value.Type(Source)))
in
#"Replaced Value"- Michael_HERE2 years agoRegular Visitor
Unfortunately, I get the same error. It occurs already in the second line.
Maybe I should have mentioned that I am using PowerQuery within Excel, not Power BI (if that matters).
Besides, the last closing parenthesis in your code is too much.
- Vijay_A_Verma2 years agoMost Valuable Professional
Is it possible to post an Excel file having 2-3 rows of dummy data to Onedrive / Google drive and share the link here?
PQ in Excel or Power BI behave the same so that won't make a difference.