Forum Discussion
Plurp
2 years agoNew Member
Categorize rows based on value in other columns
Hello! I've got a set of data that formatted similar to the table on the left in the picture below. I want to be able to categorize the rows based on the values the values in column1, resulting i...
- Anonymous2 years ago
Hi Plurp , you can consider using Text.Contains search and Text.AfterDelimiter exact the Category, and the fill down to achieve the result. Then remove the rows containing Category and Date.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck4sSU3PL6pUMDK3UgjJryxW0lFSitWJVnIBSsDYhob6hvpGBkbGQAEVcz0DA5ioEVzUEEnUGC5qDBMNyS9JzFFIyy9SQLIQrA+uES5hamCl4Jafn4LNJRZIhpvBdFromyDcYYQQNYWLWiIEzTA9gsVxpgZg55uAlcQCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = false]), _n = (( Currency.Type ) meta [Serialized.Text = false]) in type table [Column1 = _t, Cost = _n]), #"Added Custom" = Table.AddColumn(Source, "Category", each if Text.Contains( [Column1] , ": ") then Text.AfterDelimiter( [Column1] , ": ") else null, type text), #"Filled Down" = Table.FillDown(#"Added Custom",{"Category"}), #"Filtered Rows" = Table.SelectRows(#"Filled Down", each not Text.Contains([Column1], "Category") and not Text.Contains([Column1], "Date")), #"Renamed Columns" = Table.RenameColumns(#"Filtered Rows",{{"Column1", "Date"}}), #"Parsed Date" = Table.TransformColumns(#"Renamed Columns",{{"Date", each Date.From(DateTimeZone.From(_)), type date}}), #"Extracted Text After Delimiter" = Table.TransformColumns(#"Parsed Date", {{"Cost", each Text.AfterDelimiter(Text.From(_, "en-GB"), "$"), type text}}), #"Changed Type" = Table.TransformColumnTypes(#"Extracted Text After Delimiter",{{"Cost", Currency.Type}}) in #"Changed Type"
Anonymous
2 years agoNot applicable
Hi Plurp , you can consider using Text.Contains search and Text.AfterDelimiter exact the Category, and the fill down to achieve the result. Then remove the rows containing Category and Date.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck4sSU3PL6pUMDK3UgjJryxW0lFSitWJVnIBSsDYhob6hvpGBkbGQAEVcz0DA5ioEVzUEEnUGC5qDBMNyS9JzFFIyy9SQLIQrA+uES5hamCl4Jafn4LNJRZIhpvBdFromyDcYYQQNYWLWiIEzTA9gsVxpgZg55uAlcQCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = false]), _n = (( Currency.Type ) meta [Serialized.Text = false]) in type table [Column1 = _t, Cost = _n]),
#"Added Custom" = Table.AddColumn(Source, "Category", each if Text.Contains( [Column1] , ": ") then Text.AfterDelimiter( [Column1] , ": ") else null, type text),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Category"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each not Text.Contains([Column1], "Category") and not Text.Contains([Column1], "Date")),
#"Renamed Columns" = Table.RenameColumns(#"Filtered Rows",{{"Column1", "Date"}}),
#"Parsed Date" = Table.TransformColumns(#"Renamed Columns",{{"Date", each Date.From(DateTimeZone.From(_)), type date}}),
#"Extracted Text After Delimiter" = Table.TransformColumns(#"Parsed Date", {{"Cost", each Text.AfterDelimiter(Text.From(_, "en-GB"), "$"), type text}}),
#"Changed Type" = Table.TransformColumnTypes(#"Extracted Text After Delimiter",{{"Cost", Currency.Type}})
in
#"Changed Type"
- Plurp2 years agoNew Member
Perfect! This solution is far more robust than even what I had in mind. Greatly appreciate your help with this.