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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Changlin
Frequent Visitor

How to combine rows with condition

Hi,

 

I have a table shown as below:

Changlin_0-1674833537632.png

I want to combine rows with the same ID and keep the values in the "Automation status", "State" and "Priority".          

IDAutomation statusStatePriority
456820Non-AutomatedDesign2
456821Non-AutomatedDesign2

 

How to implement this goal?

 

Thanks,

 

Richard

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

This M code will get you from image1 to image2

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjE1szAyUNJRckktSS3KzcxLBbKhKFYHh7xffomCY2lJfm5iSWoKIcVgbnFmWh4hVUBkhFBgSIqd6Iqx24lFFcTOWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, name = _t, #"Automstion Status" = _t, State = _t, Priority = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"name", type text}, {"Automstion Status", type text}, {"State", type text}, {"Priority", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Automation statu", each List.Max([Automstion Status]), type nullable text}, {"State", each List.Max([State]), type nullable text}, {"Priority", each List.Sum([Priority]), type nullable number}})
in
    #"Grouped Rows"

Hope this helps.

Untitled.pngUntitled1.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

v-xinruzhu-msft
Community Support
Community Support

Hi @Changlin 

You can refer to the following example.

1.Put the following code to Advanced Editor in Power Query

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjE1szAyUNJRckktSS3KzcxLBbKhKFYHh7xffomCY2lJfm5iSWoKIcVgbnFmWh4hVUBkhFBgSIqd6Iqx24lFFcTOWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, name = _t, #"Automstion Status" = _t, State = _t, Priority = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"name", type text}, {"Automstion Status", type text}, {"State", type text}, {"Priority", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Automation statu", each List.Max([Automstion Status]), type nullable text}, {"State", each List.Max([State]), type nullable text}, {"Priority", each List.Sum([Priority]), type nullable number}})
in
    #"Grouped Rows"

 

 

vxinruzhumsft_0-1675132289928.png

 

2.You can create a new calculated table

 

 

Table 2 = SUMMARIZE('Table (2)',[ID],"Automation status",MAX('Table (2)'[Automstion Status]),"State",MAX('Table (2)'[State]),"Priority",SUM('Table (2)'[Priority]))

 

 

vxinruzhumsft_1-1675132439767.png

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-xinruzhu-msft
Community Support
Community Support

Hi @Changlin 

You can refer to the following example.

1.Put the following code to Advanced Editor in Power Query

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjE1szAyUNJRckktSS3KzcxLBbKhKFYHh7xffomCY2lJfm5iSWoKIcVgbnFmWh4hVUBkhFBgSIqd6Iqx24lFFcTOWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, name = _t, #"Automstion Status" = _t, State = _t, Priority = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"name", type text}, {"Automstion Status", type text}, {"State", type text}, {"Priority", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Automation statu", each List.Max([Automstion Status]), type nullable text}, {"State", each List.Max([State]), type nullable text}, {"Priority", each List.Sum([Priority]), type nullable number}})
in
    #"Grouped Rows"

 

 

vxinruzhumsft_0-1675132289928.png

 

2.You can create a new calculated table

 

 

Table 2 = SUMMARIZE('Table (2)',[ID],"Automation status",MAX('Table (2)'[Automstion Status]),"State",MAX('Table (2)'[State]),"Priority",SUM('Table (2)'[Priority]))

 

 

vxinruzhumsft_1-1675132439767.png

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Ashish_Mathur
Super User
Super User

Hi,

This M code will get you from image1 to image2

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjE1szAyUNJRckktSS3KzcxLBbKhKFYHh7xffomCY2lJfm5iSWoKIcVgbnFmWh4hVUBkhFBgSIqd6Iqx24lFFcTOWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, name = _t, #"Automstion Status" = _t, State = _t, Priority = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"name", type text}, {"Automstion Status", type text}, {"State", type text}, {"Priority", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Automation statu", each List.Max([Automstion Status]), type nullable text}, {"State", each List.Max([State]), type nullable text}, {"Priority", each List.Sum([Priority]), type nullable number}})
in
    #"Grouped Rows"

Hope this helps.

Untitled.pngUntitled1.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
SivaMani
Resident Rockstar
Resident Rockstar

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.