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
mraka9
Helper III
Helper III

How to link related items?

Greeting,
I need help regarding the table below.
I have a column:
Product A i
Product B.
I want to get the result for Product C.
I need in Power Query that based on Product B, Product A is searched and all sales items are added to Product B.
Examples:
Find Mobile-12 where it is in Product A and summarize all related items in Product C, which are Mobile-24 and Mobile-50.
I need a formula, not a join of tables, because there is a large amount of data.
Thank you very much in advance

 

Product AProduct BProduct C
Mobile-24Mobile-12Mobile-24;Mobile-50
Car-13Car-7Car-10;Car-13
Mobile-12Mobile-24 
Car-7Car-10 
House-30House-22 
Car-7Car-13 
House-22House-30 
Mobile-12Mobile-50 
1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @mraka9 

You can put the following code in Advanced Editor in power query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s1PysxJ1TUyUdKBsQ2NlGJ1opWcE4t0DY2BwiCGOVgIoUAHSSNMsTlUraEBWMgjv7Q4VdfYACgKYRoZYSo1RlJqZARXamyAyz5ToEwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product A" = _t, #"Product B" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product A", type text}, {"Product B", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", (x)=>Text.Combine(Table.SelectRows(#"Changed Type",(y)=>y[Product A]=x[Product B] )[Product B] ,",")       )
in
    #"Added Custom"

Output:

vxinruzhumsft_0-1673235068603.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

4 REPLIES 4
v-xinruzhu-msft
Community Support
Community Support

Hi @mraka9 

You can put the following code in Advanced Editor in power query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s1PysxJ1TUyUdKBsQ2NlGJ1opWcE4t0DY2BwiCGOVgIoUAHSSNMsTlUraEBWMgjv7Q4VdfYACgKYRoZYSo1RlJqZARXamyAyz5ToEwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product A" = _t, #"Product B" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product A", type text}, {"Product B", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", (x)=>Text.Combine(Table.SelectRows(#"Changed Type",(y)=>y[Product A]=x[Product B] )[Product B] ,",")       )
in
    #"Added Custom"

Output:

vxinruzhumsft_0-1673235068603.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

The solution is great! I don't understand why it doesn't work in my file.
Thanks a lot in advance!

 

PNG.png

Hi @mraka9 

You can try the following ways:

1.Delete "each" from your code.

2.Add a blank step:

vxinruzhumsft_0-1673314454604.png

then copy the sample code to the step

= Table.AddColumn(#"Changed Type", "Custom", (x)=>Text.Combine(Table.SelectRows(#"Changed Type",(y)=>y[Product A]=x[Product B] )[Product B] ,","))

if the table name or column name is different from yours, you need to change it.

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Unfortunately, the data is being processed for a long time, but there are no results. Anyway, I'll accept your solution as it's great, although I can't get it to work on my base. Thanks again

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.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

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
Top Kudoed Authors