Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Merge & Sum Rows in Transform Data based on Multiple Criteria

So I have this table with locations named with IDs. Each ID can have data from multiple years, and multiple metric types. I want to merge and sum all the Water + Irrigation rows with matching ID/Year, and leave all the rest as-is. I want to do this in transform data, because I have other things I need to do with this table and data. Is this possible? 

 

Original Table:

RowIDYearMetric TypeJanuary Use
1122022Water25
2122022Irrigation55
3122021Electrcitiy28160
4122022Electricity19760
54232022Water46
64232022Irrigation33
74232022Natural Gas6340

8

89

2021Electricity21780
9892022Natural Gas180
10552022Water11

 

Desired Table

RowIDYearMetric TypeJanuary Use
1122022Water80
2122021Electrcitiy28160
3122022Electricity19760
44232022Water79
54232022Natural Gas6340

6

89

2021Electricity21780
7892022Natural Gas180
8552022Water11

 

 

  • My suggestion would be to replace Irrigation as Water using replace values and then group by ID, Year and Metric Type, summing the January Use row. You can add in an index column after if it is needed.

4 Replies

  • My suggestion would be to replace Irrigation as Water using replace values and then group by ID, Year and Metric Type, summing the January Use row. You can add in an index column after if it is needed.

    • Anonymous's avatar
      Anonymous
      Not applicable

      This was such a simple step forward, thank you!

       

      Something I left out of my original solution was that I have multiple columns (one for each month), that I needed summed separately, but I actually just unpivoted them, then grouped by ID, Year, Month, and Metric and that seems to have done the trick! 

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Anonymous Sure, there is the ability to group rows in Power Query or you can use SUMMARIZE or GROUPBY in DAX.