Forum Discussion
How can I split a text string and reverse the order it splits (so first comes out last)?
- 3 years ago
Hello, OneWithQuestion
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtI1MNQJTsxJLdYJLskvSrU0MtUJSk3PzM8zVIrVgSkxQlZiYWoCVWKEpMQUWYmRsSkWJSgWGQC5ECXGSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CurrentInput = _t]), column_names = { "Date", "Category", "Store", "Region" }, output_goal = Table.ReorderColumns( Table.FromRows( List.Transform( Source[CurrentInput], Splitter.SplitTextByDelimiter(",") ), column_names ), List.Reverse(column_names) ) in output_goal - 3 years ago
no. It won't work. To retain all other columns lets transform column items to list >> list reverse >> list to record with known names and finally expand this column of records.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtI1MNQJTsxJLdYJLskvSrU0MtUJSk3PzM8zVNJRSgTiVKVYHZhSI2SlFqYmUKVGQGVJQJyGpNQUWamRsSmS0mQgTkdSiuIAAyAXotQYqCwFiDOUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CurrentInput = _t, other_column01 = _t, other_column02 = _t]), column_names = { "Region", "Store", "Category", "Date" }, output_goal = Table.ExpandRecordColumn( Table.TransformColumns( Source, { {"CurrentInput", (x) => Record.FromList( List.Reverse( Splitter.SplitTextByDelimiter(",")(x) ), column_names ) } } ), "CurrentInput", column_names ) in output_goal
Thank you so much!
I'm trying to properly understand this and adapt it.
I'm running into an issue with retaining existing columns in the table.
If in the example I provided, I wanted to only split the first column (which you did) but KEEP those other columns in the table, how does the syntax work for that?
How can you use Table.ReorderColumns to only address specific columns instead of the entire table?
no. It won't work. To retain all other columns lets transform column items to list >> list reverse >> list to record with known names and finally expand this column of records.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtI1MNQJTsxJLdYJLskvSrU0MtUJSk3PzM8zVNJRSgTiVKVYHZhSI2SlFqYmUKVGQGVJQJyGpNQUWamRsSmS0mQgTkdSiuIAAyAXotQYqCwFiDOUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CurrentInput = _t, other_column01 = _t, other_column02 = _t]),
column_names = { "Region", "Store", "Category", "Date" },
output_goal =
Table.ExpandRecordColumn(
Table.TransformColumns(
Source,
{
{"CurrentInput",
(x) =>
Record.FromList(
List.Reverse(
Splitter.SplitTextByDelimiter(",")(x)
),
column_names
)
}
}
),
"CurrentInput",
column_names
)
in
output_goal