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
melo4
2 years agoRegular Visitor
I've split the values outside of the query with combination of "LEFT" / "RIGHT" / "LEN" / "SEARCH" formulas.
I tried changing the data type in the query just like you said, but I get an error in the cells.
I also tried chaning the cell types to numbers and percentages where I have the formula, but still i always get #VALUE! errors.
Payeras_BI
2 years agoSolution Sage
Hi melo4 ,
Then this is an Excel problem, not a Power Query problem.
Try wrapping your Excel formula used to split the values with NUMBERVALUE like this:
=NUMBERVALUE(yourExcelFormulaForTheSplit,".")