Forum Discussion

TheHans's avatar
TheHans
Helper I
4 years ago
Solved

Generate a new table with different values per ID

Dear Community,   I have a table with different report dates containing different values for the same ID.  For IssueID 1, the due date has changed over time. I would like to create a new table wit...
  • BA_Pete's avatar
    4 years ago

    Hi TheHans ,

     

    Paste this over the default code in a new blank query:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLQMzDSMzIwMlLSUTIEYkcQbapnYAwRjNVBUwPCTiA1BrjVGAOxM0iNIYoakLEYdgEV4FSDwy4UNbjswuYvI4RGDDW47CLkr1gA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ReportDate = _t, IssueID = _t, IssueName = _t, DueDate = _t]),
        chgTypes = Table.TransformColumnTypes(Source,{{"DueDate", type date}}),
        remOthCols = Table.SelectColumns(chgTypes,{"IssueID", "DueDate"}),
        chgDueDateToText = Table.TransformColumnTypes(remOthCols,{{"DueDate", type text}}),
        groupRows =
            Table.Group(
                chgDueDateToText,
                {"IssueID"},
                {
                    {"noofDiffDueDates", each Table.RowCount(Table.Distinct(_)), Int64.Type},
                    {"dueDates", each Text.Combine(List.Distinct([DueDate]), ", "), type text}
                }
            )
    in
        groupRows

     

     

    The 'groupRows' step is a customised Group By function, so you may need to add this as a custom step into your query.

     

    This gives the following output:

     

    Pete