Forum Discussion
melo4
2 years agoRegular Visitor
Split column by two criteria
Hi, I am taking German equity data from investing.com and the price, change and change% are aggregated in one column. How do I split these three numbers based on two criteria (+ and -) so that it...
- 2 years ago
v1
let Source = Web.Page(Web.Contents("https://www.investing.com/equities/germany")), Data = Source{0}[Data], Transform = Table.TransformColumns(Data, List.Transform(Table.ColumnNames(Data), (colName)=> {colName, each Text.Combine(List.Transform(Text.Split(_, "#(lf)"), (x)=> Text.Trim(x, {" ", "#(lf)", "#(cr)"}) ), " "), type text})), #"Added Custom" = Table.AddColumn(Transform, "Custom", each Text.Combine(List.Transform(Splitter.SplitTextByCharacterTransition((x)=> not List.Contains({"+", "-"}, x), (y)=> List.Contains({"+", "-", "#(lf)", "#(cr)"}, y))([Column2]), (x)=> Text.Trim(x, {" ", "#(lf)", "#(cr)"})), "|"), type text), #"Split Column by Delimiter" = Table.SplitColumn(#"Added Custom", "Custom", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Price", "Change", "Change %"}), #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Price", type number}, {"Change", type number}, {"Change %", Percentage.Type}}, "en-US") in #"Changed Type"v2
let Source = Web.Page(Web.Contents("https://www.investing.com/equities/germany")), Data = Source{0}[Data], Transform = Table.TransformColumns(Data, List.Transform(Table.ColumnNames(Data), (colName)=> {colName, each Text.Combine(List.Transform(Text.Split(_, "#(lf)"), (x)=> Text.Trim(x, {" ", "#(lf)", "#(cr)"}) ), " "), type text})), Ad_List = Table.AddColumn(Transform, "List", each Splitter.SplitTextByCharacterTransition((x)=> not List.Contains({"+", "-"}, x), (y)=> List.Contains({"+", "-"}, y))([Column2]), type list), Ad_Table = Table.AddColumn(Ad_List, "Table", each List.Accumulate( List.Zip({ {0..List.Count([List])-1}, {"Price", "Change", "Change %"} }), #table(type table[Column1=text], {{[Column1]}}), (s,c)=> Table.AddColumn(s, c{1}, (x)=> Number.From([List]{c{0}}, "en-US"), if c{1} = "Change %" then Percentage.Type else type number) ), type table), Combined = Table.Combine(Ad_Table[Table]) in Combined
HotChilli
2 years agoCommunity Champion
"but the problem is that it's treating it as text" so you have successfully split the column already? It looks like you just need to change the data type of the column (which is straightforward right-click the column header->Change Type or use the Home tab : ->Data type:)