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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Consolidate Rows Aggregating some columns and keeping the first record for another column

I have multiple rows of data that I need to consolidate into one row.  Some columns are aggregated (Sum) and ONE column has different values but I need to maintain ONLY the first value. 

 

My data is as follows:

Database NameAccount NumberNameAmount
CN100012ABC, Co. Inc.50
CN100012ABC, Co. Inc. (2)100
CN100012ABC200

 

 

My desired result is:

Database NameAccount NumberNameAmount
CN100012ABC, Co. Inc.350

 

Any help is GREATLY appreciated!!

 

1 ACCEPTED SOLUTION
olgad
Resident Rockstar
Resident Rockstar

Hi there,

you can try getting what you want in Power Query, 
Transform-Group By-Advanced- for the name pick Max/Min as aggregation, for the amount-sum.

olgad_0-1673545383267.png

Once done, go to M-Code and change Max/Min to the First. 

olgad_1-1673545501009.png

and there you have it.

olgad_2-1673545532423.png

Hope that helps. 

 


DID I ANSWER YOUR QUESTION? PLEASE MARK MY POST AS A SOLUTION! APPRECIATE YOUR KUDO/LIKE!
PROUD TO BE A SUPER USER!
Best Stories, Interesting Cases: PowerBI Storytime Newsletter
Linkedin Profile: Linkedin
YouTube Channel: PowerBI Storytime

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

You can group by Database Name and Account Number, and choose the Sum aggregation for Amount, and an All Rows aggregation--name that column "Details". Once that's done, add a step:

 

= Table.AddColumn(PriorStepOrTableName, "Name", each [Details]{0})

 

--Nate

hi @Anonymous ,

 

Thanks for the response.

Just curious:

 

this will dynamically adjust based on grouped database name and account number right? or based on the index, it provides only the first value in the details column?

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash
adudani
Memorable Member
Memorable Member

hi @Anonymous ,

 

try this:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckksSUxKLE5V8EvMTVXSUXJMTs4vzStR8CvNTUotAgrAxHNBwkqxOtFKzn5AvqGBgYGhEUjCyVlHwTlfT8EzL1kPyDc1IKRIQcNIEyKJXSWQNALJxQIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Database Name", type text}, {"Account Number", Int64.Type}, {"Name", type text}, {"Amount", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Database Name", "Account Number"}, {{"Amount", each List.Sum([Amount]), type nullable number}, {"Name", each List.Median([Name]), type nullable text}})
in
#"Grouped Rows"

 

adudani_0-1673545579396.png

 

If List.Median([Name]) doesn't work, let me know.

 

Appreciate a thumbs up if this is helpful.

 

Please accept this as the solution if your query is resolved.

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash
olgad
Resident Rockstar
Resident Rockstar

Hi there,

you can try getting what you want in Power Query, 
Transform-Group By-Advanced- for the name pick Max/Min as aggregation, for the amount-sum.

olgad_0-1673545383267.png

Once done, go to M-Code and change Max/Min to the First. 

olgad_1-1673545501009.png

and there you have it.

olgad_2-1673545532423.png

Hope that helps. 

 


DID I ANSWER YOUR QUESTION? PLEASE MARK MY POST AS A SOLUTION! APPRECIATE YOUR KUDO/LIKE!
PROUD TO BE A SUPER USER!
Best Stories, Interesting Cases: PowerBI Storytime Newsletter
Linkedin Profile: Linkedin
YouTube Channel: PowerBI Storytime
Anonymous
Not applicable

@olgad THANK YOU SO MUCH!!  It worked PERFECTLY!! 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.