Power Query question - how to separate out a specific row into its own column?

ExcelOnTheClock

New Member
Joined
Dec 1, 2022
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi folks--I have a table structured like below:

1681611542522.png


I want to put Communication Services and Consumer Discretionary into their own column, so then I can fill down and aggregate these stocks. Is there a way to do this in Power Query? Preferably without using the Advanced Editor? If the Advanced Editor is required that's totally fine. My coworkers are intimidated by the advanced editor, so if can show them how to do this with just mouse clicks, that's always ideal. I want it to look like this:

1681611702316.png


The data lives HERE, let me know if the link doesn't work.

Thanks in advance for any help!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    tbl1 = Table.FillDown(Table.AddColumn(Source, "Sector", each if Text.Length([Identifier]) <= 5 then null else [Identifier]),{"Sector"}),
    tbl2 = Table.ReorderColumns(tbl1,{"Identifier", "Sector", "Weight"}),
    Result = Table.SelectRows(tbl2, each Text.Length([Identifier]) <= 5)
in
    Result

Book1
ABCDEFG
1IdentifierWeightIdentifierSectorWeight
2Communication Services94.20%METACommunication Services0.1944
3META19.44%GOOGLCommunication Services0.1815
4GOOGL18.15%GOOGCommunication Services0.1593
5GOOG15.93%DISCommunication Services0.073
6DIS7.30%VZCommunication Services0.0655
7VZ6.55%CMCSACommunication Services0.0635
8CMCSA6.35%NFLXCommunication Services0.0611
9NFLX6.11%TCommunication Services0.0564
10T5.64%TMUSCommunication Services0.0353
11TMUS3.53%ATVICommunication Services0.0242
12ATVI2.42%CHTRCommunication Services0.0145
13CHTR1.45%EACommunication Services0.0132
14EA1.32%AMZNConsumer Discretionary0.2668
15Consumer Discretionary75.16%TSLAConsumer Discretionary0.1461
16AMZN26.68%HDConsumer Discretionary0.087
17TSLA14.61%MCDConsumer Discretionary0.0619
18HD8.70%NKEConsumer Discretionary0.0461
19MCD6.19%SBUXConsumer Discretionary0.036
20NKE4.61%LOWConsumer Discretionary0.0356
21SBUX3.60%BKNGConsumer Discretionary0.0298
22LOW3.56%TJXConsumer Discretionary0.0261
23BKNG2.98%ORLYConsumer Discretionary0.0162
24TJX2.61%
25ORLY1.62%
26
Sheet2
 
Upvote 1
Solution
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    tbl1 = Table.FillDown(Table.AddColumn(Source, "Sector", each if Text.Length([Identifier]) <= 5 then null else [Identifier]),{"Sector"}),
    tbl2 = Table.ReorderColumns(tbl1,{"Identifier", "Sector", "Weight"}),
    Result = Table.SelectRows(tbl2, each Text.Length([Identifier]) <= 5)
in
    Result

Book1
ABCDEFG
1IdentifierWeightIdentifierSectorWeight
2Communication Services94.20%METACommunication Services0.1944
3META19.44%GOOGLCommunication Services0.1815
4GOOGL18.15%GOOGCommunication Services0.1593
5GOOG15.93%DISCommunication Services0.073
6DIS7.30%VZCommunication Services0.0655
7VZ6.55%CMCSACommunication Services0.0635
8CMCSA6.35%NFLXCommunication Services0.0611
9NFLX6.11%TCommunication Services0.0564
10T5.64%TMUSCommunication Services0.0353
11TMUS3.53%ATVICommunication Services0.0242
12ATVI2.42%CHTRCommunication Services0.0145
13CHTR1.45%EACommunication Services0.0132
14EA1.32%AMZNConsumer Discretionary0.2668
15Consumer Discretionary75.16%TSLAConsumer Discretionary0.1461
16AMZN26.68%HDConsumer Discretionary0.087
17TSLA14.61%MCDConsumer Discretionary0.0619
18HD8.70%NKEConsumer Discretionary0.0461
19MCD6.19%SBUXConsumer Discretionary0.036
20NKE4.61%LOWConsumer Discretionary0.0356
21SBUX3.60%BKNGConsumer Discretionary0.0298
22LOW3.56%TJXConsumer Discretionary0.0261
23BKNG2.98%ORLYConsumer Discretionary0.0162
24TJX2.61%
25ORLY1.62%
26
Sheet2
Awesome, thank you so much! It works.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top