Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
TheHans
Helper I
Helper I

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 with the columns "IssueID", "AmountDiffDueDates" and "DueDates" which contains all different due dates comma separated.

Is there a way how I can do that in PoweQuery?

Thanks a lot in advance.

 

ReportDateIssueIDIssueNameDueDate
20.02.20221A15.03.2022
20.02.20222B10.03.2022
20.02.20223C11.03.2022
15.02.20221A03.03.2022
15.02.20222B10.03.2022
15.02.20223C11.03.2022
10.02.20221A25.02.2022
10.02.20222B10.03.2022
10.02.20223C11.03.2022
1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

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:

BA_Pete_0-1645691898505.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

5 REPLIES 5
BA_Pete
Super User
Super User

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:

BA_Pete_0-1645691898505.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Wow!! This is awesome! Thanks a lot. It was really easy to use your code. How did you create that source? I never saw that before. 

Do you use the advanced editor to write that custom "groupRows" code?

Cheers

Hans

@TheHans ,

 

The source was created by pasting your example table into 'Enter Data' in Power Query. PQ represents this as a JSON Binary in text format.

 

To create the custom step, I first used Group By from the GUI, but added the second column as SUM of [DueDate]. This outputs an error, but very quickly sets up the code structure needed. I then used Advanced Editor to adjust the code for the second column to include functions (List.Distinct, Text.Combine) that aren't available via the GUI.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




 

FYI, I've just noticed that I didn't specify the output data type on the second column.

I've update the code slightly so it outputs as text type, so you don't need to do another Changed Types step afterwards.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Even better. Thanks.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.