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
William_Moreno
Helper II
Helper II

To convert vertical table into horizontal table in powerbi

Hi guys, 

I have faced problem to solver this case:

 

I have the table below:

Order_IDMovDate
10050050110510/08/2020
10050050110511/08/2020
10050050110512/08/2020
10050050110513/08/2020
10050050110514/08/2020

 

I want to convert in this table:

Order_IDDate1Date2Date3Date4Date5
10050050110/08/202011/08/202012/08/202013/08/202014/08/2020

 

Is it possible in PowerBI?

 

Thanks!

1 ACCEPTED SOLUTION
v-zhenbw-msft
Community Support
Community Support

Hi @William_Moreno ,

 

We can use some transformations in Power Query Editor to meet your requirement.

 

1. Copy the table and delete the Mov column.

 

C1.jpg

 

2. Group the Order_ID column.

 

C2.jpg

 

3. Add a custom column to get the Date column.

 

C3.jpg

 

4. Extract the Custom column by comma.

 

C4.jpg

 

5. At last, split the column.

 

C5.jpg

 

The whole M query as following,

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMAUhQyUdINsUSBoZGBnoW+gbGijF6uCTNyQgb0RA3piAvAmKvBFY3gwmb6hviF/aCL+0MX5pAnabKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Order_ID = _t, Mov = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Mov"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"Order_ID"}, {{"Data", each _, type table [Order_ID=nullable text, Date=nullable date]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Column([Data],"Date")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    #"Removed Columns1" = Table.RemoveColumns(#"Extracted Values",{"Data"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns1", "Custom", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Custom.1", "Custom.2", "Custom.3", "Custom.4", "Custom.5"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Order_ID", Int64.Type}, {"Custom.1", type date}, {"Custom.2", type date}, {"Custom.3", type date}, {"Custom.4", type date}, {"Custom.5", type date}})
in
    #"Changed Type1"

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

View solution in original post

5 REPLIES 5
v-zhenbw-msft
Community Support
Community Support

Hi @William_Moreno ,

 

How about the result after you follow the suggestions mentioned in my original post?

Could you please provide more details or expected result about it If it doesn't meet your requirement?

If you've fixed the issue on your own please kindly share your solution. If the above posts help, please kindly mark it as a solution to help others find it more quickly.

 

Best regards,

 

Community Support Team _ zhenbw

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

v-zhenbw-msft
Community Support
Community Support

Hi @William_Moreno ,

 

We can use some transformations in Power Query Editor to meet your requirement.

 

1. Copy the table and delete the Mov column.

 

C1.jpg

 

2. Group the Order_ID column.

 

C2.jpg

 

3. Add a custom column to get the Date column.

 

C3.jpg

 

4. Extract the Custom column by comma.

 

C4.jpg

 

5. At last, split the column.

 

C5.jpg

 

The whole M query as following,

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMAUhQyUdINsUSBoZGBnoW+gbGijF6uCTNyQgb0RA3piAvAmKvBFY3gwmb6hviF/aCL+0MX5pAnabKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Order_ID = _t, Mov = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Mov"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"Order_ID"}, {{"Data", each _, type table [Order_ID=nullable text, Date=nullable date]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Column([Data],"Date")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    #"Removed Columns1" = Table.RemoveColumns(#"Extracted Values",{"Data"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns1", "Custom", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Custom.1", "Custom.2", "Custom.3", "Custom.4", "Custom.5"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Order_ID", Int64.Type}, {"Custom.1", type date}, {"Custom.2", type date}, {"Custom.3", type date}, {"Custom.4", type date}, {"Custom.5", type date}})
in
    #"Changed Type1"

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

pranit828
Community Champion
Community Champion

HI @William_Moreno 

 

Use pivot table 

https://databear.com/power-bi-pivot-and-unpivot-columns/





PBI_SuperUser_Rank@1x.png


Hope it resolves your issue? 
Did I answer your question? Mark my post as a solution!

Appreciate your Kudos, Press the thumbs up button!!
Linkedin Profile

Thank you for your answer but, the corvesion has to be developed in another table!

It means that the vertical table is the table 1 e horizontal table is table 2 in power bi.

Thanks in advanced.

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.