Forum Discussion
Anonymous
2 years agoNot applicable
Create a new column by group
I have a dataframe like this group country type value a japan AB 1000 a japan - AC AB 500 a Mexico - AC CD 630 a USA AB 1400 b japan CD 1000 b japan - AC C...
- 2 years ago
Table.AddColumn( Source, "Custom", each Text.Trim( if Text.EndsWith([country], "- AC") then Text.Range([country], 0, Text.Length([country]) - 4) else [country] ) ) - 2 years ago
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUcpKLEjMUwAyHJ2AhKGBgYFSrA6ylIKugqMzTN4USdo3tSIzOR8m7ewCJMyMEdKhwY5wU02g2pKQLQTrgFuIkEI2ECEHNA7FJSgy2LVAHAh3BLLbkUyDONwAVRLZJhOwXCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [group = _t, country = _t, #"type" = _t, value = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"group", type text}, {"country", type text}, {"type", type text}, {"value", Int64.Type}}), #"Extracted country" = Table.TransformColumns(#"Changed Type", {"country", each Text.Trim(Text.BeforeDelimiter(_,"-"))}) in #"Extracted country"
ThxAlot
2 years agoSuper User
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUcpKLEjMUwAyHJ2AhKGBgYFSrA6ylIKugqMzTN4USdo3tSIzOR8m7ewCJMyMEdKhwY5wU02g2pKQLQTrgFuIkEI2ECEHNA7FJSgy2LVAHAh3BLLbkUyDONwAVRLZJhOwXCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [group = _t, country = _t, #"type" = _t, value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"group", type text}, {"country", type text}, {"type", type text}, {"value", Int64.Type}}),
#"Extracted country" = Table.TransformColumns(#"Changed Type", {"country", each Text.Trim(Text.BeforeDelimiter(_,"-"))})
in
#"Extracted country"