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

Transform and aggregate data

Hi all

 

This one has me stumped. What I want to do, is create a table with a customer case number, the customer's name and their forms of contact (phone, email and such like). It isn't working and it's because of the structure of my data, which looks like the below.

Capture.JPG

My case numbers are unique, my customer IDs are unique and everything relates well in PowerBI, but the way the data is formatted in table 3 is stuffing things up. 

 

What I want is for each customerID to be its own row, with the contact types to be columns of their own., like the below, if possible.

Capture2.JPG

The problem I have is that there are numerous customers with multiples of the same contact type, like 117 John A in my example above, so pivoting gives me errors. Short of asking my IT team to fix the format of the data set, is there anything I can do in PowerBI to fix it?

 

(Also, I should point out that the real tables are just under a million rows large.)

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous ,

 

You can refer to following sample to transform your query table based on grouping and splitcolumn functions:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ0V9JRCsjIz0sF0qampoZGxiZKsTrYZUyRZFxzEzNzgHRWfkZeokM6iKeXnJ8LVWGBqtfM3MISKmOJrDcxN7U42SEjvwRNOxZFaDYYGaDaYGxiagaVMUSVMbC0MMcuY2IMFEHIwC3MzE11yC8tycnPz4ZYGAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Customer ID" = _t, #"Contact Type" = _t, Detail = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer ID", Int64.Type}, {"Contact Type", type text}, {"Detail", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Customer ID"}, {{"Contents", each Table.Group(Table.RemoveColumns(_,{"Customer ID"}), {"Contact Type"}, {{"Content", each Text.Combine(_[Detail],","), type table}}), type table}}),
    #"Expanded Contents" = Table.ExpandTableColumn(#"Grouped Rows", "Contents", {"Contact Type", "Content"}, {"Contact Type", "Contents"}),
    #"Pivoted Column" = Table.Pivot(#"Expanded Contents", List.Distinct(#"Expanded Contents"[#"Contact Type"]), "Contact Type", "Contents"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Pivoted Column", "Phone", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Phone1", "Phone2"}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Split Column by Delimiter", "Email", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Email1", "Email2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Phone1", Int64.Type}, {"Phone2", Int64.Type}, {"Email1", type text}, {"Email2", type text}})
in
    #"Changed Type1"

19.png

 

Regards,

Xiaoxin Sheng

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.