Forum Discussion

-marie-'s avatar
-marie-
Frequent Visitor
4 years ago
Solved

Random Sorting and Grouping into 10

Hi All,    i have a list of persons i want to sort first random and then group into a group size of two persons for each group. Does anyone have a idea how to do this smart?    I figured out if R...
  • Vijay_A_Verma's avatar
    4 years ago

    See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgtKs7PU3BUitWBc5yQOc7IHBdkjisyxw2Z447M8UDmeCrFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
        #"Added Custom" = Table.AddColumn(Source, "Custom", each Number.Random(), type number),
        #"Sorted Rows" = Table.Sort(Table.Buffer(#"Added Custom"),{{"Custom", Order.Ascending}}),
        #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type),
        #"Divided Column" = Table.TransformColumns(#"Added Index", {{"Index", each _ / 2, type number}}),
        #"Rounded Up" = Table.TransformColumns(#"Divided Column",{{"Index", Number.RoundUp, Int64.Type}}),
        #"Added Custom1" = Table.AddColumn(#"Rounded Up", "Group", each "Group "&Text.From([Index])),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom", "Index"})
    in
        #"Removed Columns"