Forum Discussion
Modifing data based on a correction table
- 4 years ago
Hi DanFromMontreal ,
Please try the following code:
let #"Unpivot tblData" = Table.UnpivotOtherColumns(tblData, {"RowID"}, "Attribute", "Value"), #"Unpivot tblCorrection" = Table.UnpivotOtherColumns(tblCorrection, {"RowID"}, "Attribute", "Value"), Source = Table.NestedJoin(#"Unpivot tblData", {"RowID", "Attribute"}, #"Unpivot tblCorrection", {"RowID", "Attribute"}, "tblCorrection", JoinKind.LeftOuter), #"Expanded tblCorrection" = Table.ExpandTableColumn(Source, "tblCorrection", {"Value"}, {"tblCorrection.Value"}), #"Added Custom" = Table.AddColumn(#"Expanded tblCorrection", "Custom", each if [tblCorrection.Value] = " " or [tblCorrection.Value] = null then [Value] else [tblCorrection.Value]), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Value", "tblCorrection.Value"}), #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "Custom") in #"Pivoted Column"If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
let
Origine = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsovN1TSUYIgZ2coM1YHLGMKZDs6wqWdnJDkLCBiLi5waZiMoQFcyNUVSLi5AQl3d6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [RowID = _t, Customer = _t, City = _t, Addres = _t, Zipcode = _t, Phone = _t]),
#"Sostituito valore" = Table.ReplaceValue(Origine,"",null,Replacer.ReplaceValue,{"Customer", "City", "Addres", "Zipcode", "Phone"})
in
#"Sostituito valore"let
Origine = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XdK7CsJAFIThd9k6wmbvW4ovIJaGVCZgCl0xEfHtBfHAzOlmmq/6h8Gc2rs3nTm81q3d5udO/rJ9ZO+n6Tmvq9zz8ri0aZZ7vLb7/4zdz3PKc+A59hx7Dj0nnleeB8+z59nz6HnxgvICeIG9wF5AL4gXlRfBi+xF9iJ6UbykvAReYi+xl9BL4mXlZfAye5m9jF4WryivgFfYK+wV9Ip4VXkVvMpeZa+iV8XrrQ7aYtFWJW1V05aitmYcvw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [RowID = _t, Customer = _t, City = _t, Addres = _t, Zipcode = _t, Phone = _t]),
#"Modificato tipo" = Table.TransformColumnTypes(Origine,{{"RowID", type text}, {"Customer", type text}, {"City", type text}, {"Addres", type text}, {"Zipcode", type text}, {"Phone", type text}}),
ncols=Table.ColumnCount(#"Modificato tipo"),
ttr=Table.TransformRows(#"Modificato tipo" , each Record.FromList(List.Transform({0..ncols-1}, (f)=> Record.FieldValues(corrtab{[RowID=[RowID]]}? ?? _){f} ?? Record.FieldValues(_){f}),Record.FieldNames(_)))
in
Table.FromRecords(ttr)
- DanFromMontreal4 years ago
Helper IV
Goog morning Anonymous ,
Thank you for answering to my post and sorry for the delay.
I have tried your solution but your last "let" is giving mr an error. It doest not recognize "corrtab" in:
ttr=Table.TransformRows(#"Modificato tipo" , each Record.FromList(List.Transform({0..ncols-1}, (f)=> Record.FieldValues(corrtab{[RowID=[RowID]]}? ?? _){f} ?? Record.FieldValues(_){f}),Record.FieldNames(_)))I therefore cannot test your solution.
No error were found in the other 2 script.
Tried to understand the error to fix it but could not.
Also, thank you for your advice about loading a file. Read the post and it is very insightful.
However, due to company's policy, the use of Dropbox, Google drive or other tool, it is strickly forbidden.
Thank you again for looking once more at your code to find the problem.
Merci beaucoup / grazie.