Forum Discussion
Cheywork91
3 years agoFrequent Visitor
dim_Range? One set of time ranges that classify multiple different columns
I have a ton of different duration columns in decimal number format. I would like to be able to put them all into ranges. EX: each if [xduration] <= .25 then "00:01-00:15" else if [xdurati...
AlienSx
Super User
3 years agoHello, Cheywork91 try this on your data. If you need to modify all columns in the table then duration/other columns selection steps are not necessary - just Table.ToColumns the whole table. Otherwise modify duration_column_names manually.
let
dt = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKjFU0lEy0IOSxkqxOkAxIzAPQhpYQMRMwTwIaWQEETMH86CkKUTM0hLMhVIWQN2xAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [c1 = _t, c2 = _t, c3 = _t]),
data_table = Table.TransformColumnTypes(dt,{{"c3", type number}, {"c2", type number}}),
lt = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LcpBDgAQDETRu3SNzNCSuIq4/zUU3fzFy19LUKpJEmCC2UuTnS6Hsl9tCB3B7c36Z35TXznh6z4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [d = _t, range = _t]),
lookup_table = Table.Sort( Table.TransformColumnTypes(lt,{{"d", type number}}), "d" ),
lookup_d = List.Buffer( lookup_table[d] ),
lookup_range = List.Buffer( lookup_table[range] ),
f = (x as list) =>
List.Transform(
x,
(w) =>
let
a = List.PositionOf( lookup_d, w, Occurrence.First, (a, b) => a >= b )
in try lookup_range{a} otherwise null
),
duration_column_names = {"c2", "c3"},
other_column_names = List.Difference( Table.ColumnNames( data_table ), duration_column_names ),
duration_columns =
List.Transform(
Table.ToColumns(
Table.SelectColumns( data_table, duration_column_names )
),
each f (_)
),
other_columns = Table.ToColumns( Table.SelectColumns(data_table, other_column_names) ),
final_table = Table.FromColumns(other_columns & duration_columns, other_column_names & duration_column_names)
in
final_table
Cheywork91
3 years agoFrequent Visitor
This looks promising, but I'm not comfortable importing an unknown JSON.
Thanks anyways