Forum Discussion
jwb3d
4 months agoFrequent Visitor
Append Column to row derived from the from three columns
I would like to include a column that is derived from the deviceName,phase and fid. This would involve appending A-B-C to each of the duplicated rows. Example fid phaseCount phase extractDate devic...
- 4 months ago
If your original data looks something like:
Then you can use this code:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtDAwMDcyUtJRcnRyBpLG+sb6RgZGZkCmS2pZZnKqoVKsTrSShZGhgYm5kaUxSCF2dQZgheYgI43NTA1AEtjUWSrFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [fid = _t, phase = _t, extractDate = _t, deviceName = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{ {"fid", Int64.Type}, {"phase", type text}, {"extractDate", type date}, {"deviceName", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "deviceNamePhase", (x)=> List.Transform( Text.ToList(x[phase]), each x[deviceName] & "_" & _ & "_" & Number.ToText(x[fid]))), #"Expanded deviceNamePhase" = Table.ExpandListColumn(#"Added Custom", "deviceNamePhase") in #"Expanded deviceNamePhase"to produce:
Hopefully this will point in the right direction.
ronrsnfld
Super User
4 months agoIf your original data looks something like:
Then you can use this code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtDAwMDcyUtJRcnRyBpLG+sb6RgZGZkCmS2pZZnKqoVKsTrSShZGhgYm5kaUxSCF2dQZgheYgI43NTA1AEtjUWSrFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [fid = _t, phase = _t, extractDate = _t, deviceName = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{
{"fid", Int64.Type}, {"phase", type text}, {"extractDate", type date}, {"deviceName", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "deviceNamePhase", (x)=>
List.Transform(
Text.ToList(x[phase]),
each x[deviceName] & "_" & _ & "_" & Number.ToText(x[fid]))),
#"Expanded deviceNamePhase" = Table.ExpandListColumn(#"Added Custom", "deviceNamePhase")
in
#"Expanded deviceNamePhase"
to produce:
Hopefully this will point in the right direction.