Forum Discussion
Replace Value using a value in different column in PowerQ
- 6 years ago
Hello PowerQPro
your code should look something like this. I just replaced my datasoure with your steps till the transformation.
let let FullPathToFile2 = Excel.CurrentWorkbook(){[Name="FilePath2"]}[Content]{0}[Column1], Source = Csv.Document(File.Contents(FullPathToFile2),[Delimiter="#(tab)", Columns=29, Encoding=65001, QuoteStyle=QuoteStyle.None]), #"Removed Top Rows" = Table.Skip(Source,13), #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]), #"Removed Top Rows1" = Table.Skip(#"Promoted Headers",2), TransformRows = Table.FromRecords(Table.TransformRows ( #"Removed Top Rows1", (row)=> let check3Fill4 = if row[_3]<> "" then Record.TransformFields(row, {"_4", each "----"}) else row, check4Fill4 = if check3Fill4[_4]<> "" then Record.TransformFields(check3Fill4, {"_5", each "----"}) else check3Fill4 in check4Fill4 )) in TransformRowsyou have to update this part according you needs. These two lines should show how to get there
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
Hello PowerQPro
i don't think that applying your logic there is a way to do that in one step with Table.ReplaceValue, because your are referencing in one step a column, that was changed in the previous step. But if you would do with Table.TransformRows it could work.
Here an code example how this could look like. This is much more readable and logic to maintain
let
Source = #table
(
{"_3","_4","_5","_6","_7","_8","_9","_10","_11"},
{
{"x","","asdf","sadf","1333,33","","asfd","",""}, {"x","","sadf","","sadf","","","sadf",""}
}
),
TransformRows = Table.FromRecords(Table.TransformRows
(
Source,
(row)=>
let
check3Fill4 = if row[_3]<> "" then Record.TransformFields(row, {"_4", each "----"}) else row,
check4Fill4 = if check3Fill4[_4]<> "" then Record.TransformFields(check3Fill4, {"_5", each "----"}) else check3Fill4
in
check4Fill4
))
in
TransformRows
Copy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query
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
Hi Jimmy
I am not an expert user to identify all the steps you created, but once embeded to the code, it is not giving any Syntax erro, but running creates an error. full code below. Please note that there are lot of columns in the table I did not mention but only need to change the onces I mentioned.
let
FullPathToFile2 = Excel.CurrentWorkbook(){[Name="FilePath2"]}[Content]{0}[Column1],
Source = Csv.Document(File.Contents(FullPathToFile2),[Delimiter="#(tab)", Columns=29, Encoding=65001, QuoteStyle=QuoteStyle.None]),
#"Removed Top Rows" = Table.Skip(Source,13),
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
#"Removed Top Rows1" = Table.Skip(#"Promoted Headers",2),
TransformRows = Table.FromRecords(Table.TransformRows
(
Source,
(row)=>
let
check3Fill4 = if row[_3]<> "" then Record.TransformFields(row, {"_4", each "----"}) else row,
check4Fill4 = if check3Fill4[_4]<> "" then Record.TransformFields(check3Fill4, {"_5", each "----"}) else check3Fill4
in
check4Fill4
))
in
TransformRows
- Jimmy8016 years agoCommunity Champion
Hello PowerQPro
your code should look something like this. I just replaced my datasoure with your steps till the transformation.
let let FullPathToFile2 = Excel.CurrentWorkbook(){[Name="FilePath2"]}[Content]{0}[Column1], Source = Csv.Document(File.Contents(FullPathToFile2),[Delimiter="#(tab)", Columns=29, Encoding=65001, QuoteStyle=QuoteStyle.None]), #"Removed Top Rows" = Table.Skip(Source,13), #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]), #"Removed Top Rows1" = Table.Skip(#"Promoted Headers",2), TransformRows = Table.FromRecords(Table.TransformRows ( #"Removed Top Rows1", (row)=> let check3Fill4 = if row[_3]<> "" then Record.TransformFields(row, {"_4", each "----"}) else row, check4Fill4 = if check3Fill4[_4]<> "" then Record.TransformFields(check3Fill4, {"_5", each "----"}) else check3Fill4 in check4Fill4 )) in TransformRowsyou have to update this part according you needs. These two lines should show how to get there
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