cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
JVos
Helper IV
Helper IV

Concatenate values from child records while expanding from merged query

Given a 'parent' table:

ROUTING_ID
1
2

 

and a 'child' table:

ROUTING_ID_FromROUTING_ID_To
125
126
127
225
226

 

How can I get the following output column 'NextRoutings', if possible in the 'ExpandTableColumn' step:

ROUTING_IDNextRoutings
125,26,27
225,26

 

This is NOT working:

= Table.ExpandTableColumn(#"Merged Queries", "qryRoutingsFromTo", List.Accumulate(qryRoutingsFromTo[ROUTING_ID_To], "", (state, current) => if state = "" then Number.ToText(current) else state & "," & Number.ToText(current)), {"ROUTING_ID_To"})

 

I also don't want to expand the table in the 'normal' way and then group it on all columns other than qryRoutingsFromTo[ROUTING_ID_To] and then 'calculcate' the NextRouting column. Reason: I think it can be done directly in the ExpandTableColumn step. I also need to group on a lot of columns.

 

Another solution could be to first group the child table (which is only on one column) and after that to merge with it. But still... can it be done in the expand-step?

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

For your purpose, "Table.ExpandTableColumn" is the wrong command, as you don't want an expansion, but an aggregation instead.

Using the UI, you have the option to select an aggregation instead: 

 

image.png

 

You can either use one of the default-options and then tweak the code:

 

Table.AggregateTableColumn(#"Merged Queries", "Table2", {{"ROUTING_ID_To", each Text.Combine(List.Transform(_, (x) => Text.From(x)), ","), "Desired Result"}})

or simply add a column with the code @v-juanli-msft  has provided already (Text.Combine[MergedChildTableColumn], ","). That delivers the desired result and you simple remove the merged column afterwards.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

5 REPLIES 5
ImkeF
Super User
Super User

For your purpose, "Table.ExpandTableColumn" is the wrong command, as you don't want an expansion, but an aggregation instead.

Using the UI, you have the option to select an aggregation instead: 

 

image.png

 

You can either use one of the default-options and then tweak the code:

 

Table.AggregateTableColumn(#"Merged Queries", "Table2", {{"ROUTING_ID_To", each Text.Combine(List.Transform(_, (x) => Text.From(x)), ","), "Desired Result"}})

or simply add a column with the code @v-juanli-msft  has provided already (Text.Combine[MergedChildTableColumn], ","). That delivers the desired result and you simple remove the merged column afterwards.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

@ImkeFThanks!

v-juanli-msft
Community Support
Community Support

Hi @JVos 

In Child table, group by ROUTING_ID_From

3.png

let
    Source = Excel.Workbook(File.Contents("C:\Users\maggiel\Desktop\case\6\6.27\6.27.xlsx"), null, true),
    Sheet3_Sheet = Source{[Item="Sheet3",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet3_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"ROUTING_ID_From", Int64.Type}, {"ROUTING_ID_To", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ROUTING_ID_From"}, {{"NextRoutings", each Text.Combine([ROUTING_ID_To]," , "), type text}})
in
    #"Grouped Rows"

Then merge child table to parent table and expand the column.

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-juanli-msft, I think you didn't read the last sentence of my question...

Hi @JVos 

But still... can it be done in the expand-step?

I can't make it work only with the expand-step.

There is some mistake in my previous post, please read again since i update.

Hope it will help you indeed.

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors