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
John1234
Frequent Visitor

Summarize by different column when blank

Hi,

 

I'm trying to create household level data for our users by using 'summarize' to group users with the same address. For example, if user A (userA@gmail.com), and user B (userB@gmail.com), live at the same address, they will be grouped together. 

 

The problem I'm running into is for users with a blank address. If a user has a blank address, I'd instead like to just use their email as the identifier, instead of the address. Example below:

 

Initial Table

AddressEmail
123 West Ln.UserA@gmail.com
123 West Ln.UserB@gmail.com
 UserC@gmail.com
 UserD@gmail.com
321 East Ln.UserE@gmail.com

 

Desired Result

 

AddressEmail
123 West Ln.UserA@gmail.com, UserB@gmail.com
 UserC@gmail.com
 UserD@gmail.com
321 East Ln.UserE@gmail.com

 

I'm not having any trouble with the concatenatex part, but getting UserC and UserD to appear on separate lines has been a challenge.

 

Apologies if this has posted multiple times, this is my first time posting and I can't seem to find the post after I submit it!

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @John1234 

you can take steps below for reference.

1. Open the Advanced editor:

v-xiaotang_0-1620639311735.png

2. Empty the contents in the Advanced editor, and copy the following code into it

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxJKUotLjZU0lFKzU3MzDFUitXBFDUCi8J4xig8E2QdpjBRU6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Address = _t, Email = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Address", type text}, {"Email", type text}}),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Address] <> "")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Address"}, {{"Email", each Text.Combine([Email],", "), type  text}}),
    table1= Table.SelectRows(Source, each ([Address] = "")),
    #"appendtable"=Table.Combine({table1, #"Grouped Rows"})
in
    #"appendtable"

 

Result:

v-xiaotang_1-1620639311736.png

Hope this helps.

 

Best Regards,

Community Support Team _ Tang

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

View solution in original post

4 REPLIES 4
v-xiaotang
Community Support
Community Support

Hi @John1234 

you can take steps below for reference.

1. Open the Advanced editor:

v-xiaotang_0-1620639311735.png

2. Empty the contents in the Advanced editor, and copy the following code into it

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxJKUotLjZU0lFKzU3MzDFUitXBFDUCi8J4xig8E2QdpjBRU6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Address = _t, Email = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Address", type text}, {"Email", type text}}),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Address] <> "")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Address"}, {{"Email", each Text.Combine([Email],", "), type  text}}),
    table1= Table.SelectRows(Source, each ([Address] = "")),
    #"appendtable"=Table.Combine({table1, #"Grouped Rows"})
in
    #"appendtable"

 

Result:

v-xiaotang_1-1620639311736.png

Hope this helps.

 

Best Regards,

Community Support Team _ Tang

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

Thank you!

DataInsights
Super User
Super User

@John1234,

 

Try this in Power Query. The original table is named Table.

 

1. Create query AddressNotNull:

 

let
    Source = Table,
    FilterRows = Table.SelectRows(Source, each ([Address] <> null)),
    ConcatEmail = Table.Group( FilterRows, {"Address"}, {{"Email", each Text.Combine([Email], ", "), type text}})
in
    ConcatEmail

 

2. Create query AddressNull:

 

let
    Source = Table,
    FilterRows = Table.SelectRows(Source, each ([Address] = null))
in
    FilterRows

 

3. Create query Append:

 

let
    Source = Table.Combine({AddressNotNull, AddressNull})
in
    Source

 

DataInsights_0-1620340171578.png

 





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

Proud to be a Super User!




Thank you! 

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.

Top Solution Authors