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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
pye
Helper I
Helper I

Combine 2 columns to one column by adding rows

Hello there,

 

I have a set of data as below in a pivot form from the 4th columns. 

The first row is read as Supplier AG produce Product Line of Footwear with total component weight of 300 kg. There are two components in the 300 kg, Rubber that made up of 40%, 120kg and Cotton that made up of 60%, 180kg.

pye_0-1675406822861.png

 

I am planning to transform/clean the table into Table 2 using power query, by removing "total component weight (kg)" and combine "component 1" and component 2" into single columns with adding rows. 

I figure out to use split Table 1 into 2, Component 1 and Component 2, and then append them. It is getting complicated because there might be more Component, 3, 4, 5 etc. in Table 1. 

pye_1-1675407132400.png

 

I tried unpivot column 4th to 6th, but I am stuck at the steps to combine the "Component" columns into one. May I have some suggestions on this? Thank you!

 

 

 

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

NewStep=#table({"Supplier","Product Line","Component","Component %","Weight (kg)"},List.TransformMany(Table.ToRows(PreviousStepName),each List.Select(List.Split(List.Skip(_,3),3),each Text.From(_{0}??"")<>""),(x,y)=>List.FirstN(x,2)&y))

View solution in original post

2 REPLIES 2
pye
Helper I
Helper I

thank you!! it worked pretty well.

wdx223_Daniel
Super User
Super User

NewStep=#table({"Supplier","Product Line","Component","Component %","Weight (kg)"},List.TransformMany(Table.ToRows(PreviousStepName),each List.Select(List.Split(List.Skip(_,3),3),each Text.From(_{0}??"")<>""),(x,y)=>List.FirstN(x,2)&y))

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors