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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Rdata
Advocate I
Advocate I

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

 

 

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

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.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

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


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
jgeddes
Super User
Super User

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.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





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! 

@Rdata Unpivot for the win!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.