cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

Group by ID and sum a column based on a third column with Power Query.

I have data coming back that look like this: 

IdYearAmount
1201015
1201020
1201220
2201010
2201130
2201140
2201115
3201210
3201320
3201320

 

I want the end result to be like this: 


 

IdYearAmount
1201035
1201220
2201010
2201185
3201210
3201340

 

So for each Id, the year should be unique, and the amount should be summed for that year. Can I do it in Power BI query editor? Do I need to write code for that? 

1 ACCEPTED SOLUTION
Microsoft
Microsoft

That depends on what you want to show in each other column, since you have fewer rows, you are going to have to determine what to show when those rows are merged for those other Columns. For example, you could add additional aggregates for each column using the max aggregate.

View solution in original post

5 REPLIES 5
Microsoft
Microsoft

That depends on what you want to show in each other column, since you have fewer rows, you are going to have to determine what to show when those rows are merged for those other Columns. For example, you could add additional aggregates for each column using the max aggregate.

View solution in original post

@artemus am not sure if I should post this as a new question, but I want to filter the "years" as >= current year, how do we do that? 

You can do oit like this:

artemus_0-1606242804431.png

 

Microsoft
Microsoft

What you need to do is a group by:

1. Select both the Id and Year column

2. Choose Group By button.

3. In the aggregations, choose Sum, and for the column choose Amount

4. Name the column Amount

Thanks @artemus .. how do I do that and keep all other columns I already chose in a previous step? When I do the grouping I lose all other columns I had already. For those other columns, they are shared between all, so I'd like keep them the same. 

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Wave Release 2

Check out the updates in Power BI.

Overview of Power BI 2020 release wave 2!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

secondImage

The largest Power BI virtual conference

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

Top Solution Authors