Aggregating certain rows with power query?

jplank

Board Regular
Joined
Sep 19, 2012
Messages
62
I'm new to Power Query and have what might be a basic question. I have my data in the following format:

Company Sales
Company A100
Company B (division 1)200
Company B (division 2)300
Company B (division 3)400
Company C500
Company D600
Company E (division 1)100
Company E (division 2)200

Is there a way to transform my data so that Company E divisions 1 and 2 are aggregated into a Company E row and similarly with Company B divisions 1, 2 and 3?

I've cross-posted this question here:


 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
grouping.png
 
Upvote 0
#1 is what I'm looking for. The actual information about divisions is not relevant for my analysis.
 
Upvote 0
#1 is what I'm looking for
sure
Code:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Type = Table.TransformColumnTypes(Source,{{"Company", type text}, {"Sales", Int64.Type}}),
    ETBD = Table.TransformColumns(Type, {{"Company", each Text.BeforeDelimiter(_, " ("), type text}}),
    Group = Table.Group(ETBD, {"Company"}, {{"Sales", each List.Sum([Sales]), type number}})
in
    Group
 
Upvote 0
Select you range and use Ctrl+T
Be sure the name of the new table is the same as in the M-code (here: Table1)
select any cell in the new Table and:
- Data - From Table
- Advanced Editor
- replace whole code there with copied from the post
- Done
- Close&Load
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

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