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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
LPenatti
Helper II
Helper II

Group equal rows removing nulls

Dear all

 

I am trying to group some rows of my data based on the first two columns, Index and Account.Name, where the value on another columns is null. The result I want is to avoid null values on the last 2 columns, is it possible to be done in power query?

 

merge it.png

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

@LPenatti 

You can do this using Group By in the Power Query interface.

 

You just have to choose an arbitrary aggregation for the Customer Care Manager & Customer Support Coordinator columns (in case there are multiple values for a given Index/Account.Name combination, which I imagine shouldn't happen).

 

In my example I used Min, which automatically ignores nulls using the List.Min function.

 

image.png

 

Here is my M code, including creating the table. The relevant step is #"Grouped Rows".

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlDSUXIuLS7Jz00tUjAEcZx9wbRSrA4WWRA/2BnIBMkaIssaQfUawfRiyEL1GoFljZBljRGyxkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, Account.Name = _t, #"Customer Care Manager" = _t, #"Customer Support Coordinator" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Index", Int64.Type}, {"Account.Name", type text}, {"Customer Care Manager", type text}, {"Customer Support Coordinator", type text}}),
    OriginalTable = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"Customer Care Manager", "Customer Support Coordinator"}),
    #"Grouped Rows" = Table.Group(OriginalTable, {"Index", "Account.Name"}, {{"Customer Care Manager", each List.Min([Customer Care Manager]), type nullable text}, {"Customer Support Coordinator", each List.Min([Customer Support Coordinator]), type nullable text}})
in
    #"Grouped Rows"

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

2 REPLIES 2
LPenatti
Helper II
Helper II

@OwenAuger It worked like a charm, thank you!

OwenAuger
Super User
Super User

@LPenatti 

You can do this using Group By in the Power Query interface.

 

You just have to choose an arbitrary aggregation for the Customer Care Manager & Customer Support Coordinator columns (in case there are multiple values for a given Index/Account.Name combination, which I imagine shouldn't happen).

 

In my example I used Min, which automatically ignores nulls using the List.Min function.

 

image.png

 

Here is my M code, including creating the table. The relevant step is #"Grouped Rows".

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlDSUXIuLS7Jz00tUjAEcZx9wbRSrA4WWRA/2BnIBMkaIssaQfUawfRiyEL1GoFljZBljRGyxkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, Account.Name = _t, #"Customer Care Manager" = _t, #"Customer Support Coordinator" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Index", Int64.Type}, {"Account.Name", type text}, {"Customer Care Manager", type text}, {"Customer Support Coordinator", type text}}),
    OriginalTable = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"Customer Care Manager", "Customer Support Coordinator"}),
    #"Grouped Rows" = Table.Group(OriginalTable, {"Index", "Account.Name"}, {{"Customer Care Manager", each List.Min([Customer Care Manager]), type nullable text}, {"Customer Support Coordinator", each List.Min([Customer Support Coordinator]), type nullable text}})
in
    #"Grouped Rows"

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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