Skip to content

Instantly share code, notes, and snippets.

@ninmonkey
Created July 9, 2020 00:52
Show Gist options
  • Save ninmonkey/ac528ee503b7861c9535b4961aac1107 to your computer and use it in GitHub Desktop.
Save ninmonkey/ac528ee503b7861c9535b4961aac1107 to your computer and use it in GitHub Desktop.
replacing one column in one record of a table
// replace bad name
let
/* ignore this chunk */
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSspPUtJRMgRiI0NjQxMTpVidaKW0otQUkAgQGxsZm5iZGUPEczOLizPz0kHCQGxibGRqZgSVgphjAtJlbGKqFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [name = _t, customer = _t, UID = _t]),
#"Changed Type" = Table.TransformColumnTypes(
Source,{
{"name", type text}, {"customer", Int64.Type}, {"UID", Int64.Type}
}),
/* select record, modify it, then call Replace
you could use: https://docs.microsoft.com/en-us/powerquery-m/table-replacevalue
*/
TargetRecord = Source{2}, // it is: [name="missing", customer=3, UID=43256234],
NewRecord = [name="Terry", customer=3, UID=43256234],
ModifiedTable = Table.ReplaceMatchingRows(
Source,
{
{TargetRecord, NewRecord}
}
)
in
ModifiedTable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment