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
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
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.