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

Combine rows by ID and transpose columns

I have the following table, where A = a number and B = some text

 

IDDataTypeValue
1NumberA
1TextB
2NumberA
2Text B
3NumberA
3TextB

 

I would like the followng output:

 

IDNumberText
1AB
2AB
3AB

 

I have tried using Group by and transposing the columns, as well as trying to create a custom column but have not been successful. Any help would be appreciated.

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @lightw0rks ,

 

If you have the table as presented you need to:

  • Select Data Type column
  • Transform
  • Pivot Columns
  • Use values of colum Text
  • Don't aggregate
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfIrzU1KLQIyDJVidSBCIakVJUDKCSxghKnGCF2NMaYaYxQ1sQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, DataType = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"DataType", type text}, {"Value", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[DataType]), "DataType", "Value")
in
    #"Pivoted Column"

 

If you don't have the datatype column you need to add the a calculated column with the following code:

if (try Number.From([Value]) otherwise "Text" ) = "Text" then "Text" else "Number"

 

then just follow the steps above using this new column


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @lightw0rks ,

 

If you have the table as presented you need to:

  • Select Data Type column
  • Transform
  • Pivot Columns
  • Use values of colum Text
  • Don't aggregate
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfIrzU1KLQIyDJVidSBCIakVJUDKCSxghKnGCF2NMaYaYxQ1sQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, DataType = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"DataType", type text}, {"Value", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[DataType]), "DataType", "Value")
in
    #"Pivoted Column"

 

If you don't have the datatype column you need to add the a calculated column with the following code:

if (try Number.From([Value]) otherwise "Text" ) = "Text" then "Text" else "Number"

 

then just follow the steps above using this new column


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks MFelix, works great!

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!

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.