cancel
Showing results for 
Search instead for 
Did you mean: 
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.

View solution in original post

amitchandak
Super User IV
Super User IV

@William_Moreno , Create a column(Sub category based on order id) Rank and and append that with Date

 

Date new = "Date " & [RanK]

 

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3...



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

pranit828
Super User II
Super User II

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
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

March Update

Check it Out!

Click here to read more about the March 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

secondImage

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.