Forum Discussion
DanFromMontreal
Helper IV
4 years agoModifing data based on a correction table
Hello dear Power BI community, I've got a good challenge that I was unable to resolve and/or find the right approach to modify several data in a table. I have a table (tblData) containing more than...
- 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.
Anonymous
4 years agoNot applicable
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}}),
#"Merge di query eseguito" = Table.NestedJoin(#"Modificato tipo", {"RowID"}, corr, {"RowID"}, "corr", JoinKind.LeftOuter),
#"Tabella corr espansa" = Table.ExpandTableColumn(#"Merge di query eseguito", "corr", {"RowID", "Customer", "City", "Addres", "Zipcode", "Phone"}, {"RowID.1", "Customer.1", "City.1", "Addres.1", "Zipcode.1", "Phone.1"}),
nrows=Table.RowCount(Origine),
ncols=Table.ColumnCount(Origine),
names=Table.ColumnNames(Origine),
ttc=Table.ToColumns(#"Tabella corr espansa"),
tr=List.Transform({0..ncols-1}, each List.Transform({0..nrows-1}, (r)=>ttc{_+6}{r}??ttc{_}{r})),
tfc=Table.FromColumns(tr,names)
in
tfc