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
Anonymous
Not applicable

Transforming data table

Hi,

 

In PowerBI i have a data Table 1, which needs to be converted a in Table 2.

Is it possible? Thanks in advance for your help.

 

Table 1:
Table 1 (from)Table 1 (from)

 

Table 2:
Table 2 (to)Table 2 (to)

 

BR,

Anabn

1 ACCEPTED SOLUTION
slorin
Super User
Super User

Hi,

 

let
Source = Your_Source,
Unpivot = Table.UnpivotOtherColumns(Source, {"ID", "Activity"}, "Attribute", "Value"),
Combine_Columns = Table.CombineColumns(Unpivot,{"Activity", "Attribute"},Combiner.CombineTextByDelimiter("_", QuoteStyle.None),"Attribute.1"),
Pivot = Table.Pivot(Combine_Columns, List.Distinct(Combine_Columns[Attribute.1]), "Attribute.1", "Value",
each Text.Combine(List.Transform(_, Text.From), " - "))
in
Pivot

Stéphane

View solution in original post

5 REPLIES 5
slorin
Super User
Super User

Hi,

 

let
Source = Your_Source,
Unpivot = Table.UnpivotOtherColumns(Source, {"ID", "Activity"}, "Attribute", "Value"),
Combine_Columns = Table.CombineColumns(Unpivot,{"Activity", "Attribute"},Combiner.CombineTextByDelimiter("_", QuoteStyle.None),"Attribute.1"),
Pivot = Table.Pivot(Combine_Columns, List.Distinct(Combine_Columns[Attribute.1]), "Attribute.1", "Value",
each Text.Combine(List.Transform(_, Text.From), " - "))
in
Pivot

Stéphane

wdx223_Daniel
Super User
Super User

=Table.Combine(Table.Group(PreviousStepName,"ID",{"n",each let a=List.Skip(Table.ColumnNames(_),2) in #table({"ID"}&List.TransformMany([Activity],each a,(x,y)=>x&"_"&y),{List.Combine(Table.Rows(Table.SelectColumns(_,a)))})})[n])

slorin
Super User
Super User

Hi,

let
Source = Your_Source,
Unpivot = Table.UnpivotOtherColumns(Source, {"ID", "Activity"}, "Attribute", "Value"),
Combine_Columns = Table.CombineColumns(Unpivot,{"Activity", "Attribute"},Combiner.CombineTextByDelimiter("_", QuoteStyle.None),"Attribute.1"),
Pivot = Table.Pivot(Combine_Columns, List.Distinct(Combine_Columns[Attribute.1]), "Attribute.1", "Value")
in
Pivot

Stéphane 

Anonymous
Not applicable

Hi, Thank you 🙂
this worked perfectly fine.
But some values have Error after Pivot, even though it had a proper date format before pivot.
ErrorError

ppm1
Solution Sage
Solution Sage

You could do it by first unpivoting the Date 1, Date 2, and Date 3 columns, create a new column that merges the first column with the new Attribute column (Date 1/2/3), and then pivoting on that new column. However, you should consider just doing the unpivot step only to set your data up for easier analysis (you could always create your design table in a visual as needed).

 

Pat

Microsoft Employee

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.

Top Solution Authors