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
eWise
Advocate I
Advocate I

Transposing columns in a Table with multiple columns

I am in  a bind trying to transpose my table which appears as below and would greatly appreciate the help.  I would like to transpose the StatusName and StatusTime so that the end product is as shown below the main table.  That way, I can calculate the time differences between the status names.

CustomerIdDeliveryIdDocumentIdShortIdStatusNameStatusTime
2255CPU6096178allocated12/3/2020 20:08
2255CPU6096178awaitingPickup12/3/2020 20:08
2255CPU6096178complete12/3/2020 22:52
2255CPU6096178delivered12/3/2020 22:52
2255CPU6096178inProgress12/3/2020 20:08
2255CPU6096178picked12/3/2020 22:52
2255CPU6096178sourcingCourier12/3/2020 20:08
22560CPU1265194allocated11/10/2020 19:25
22560CPU1265194awaitingPickup11/10/2020 19:25
22560CPU1265194complete11/10/2020 23:36
22560CPU1265194delivered11/10/2020 23:36
22560CPU1265194inProgress11/10/2020 19:25
22560CPU1265194inTransit11/10/2020 22:19
22560CPU1265194picked11/10/2020 22:19
22560CPU1265194pickedUp11/10/2020 22:19
22560CPU1265194sourcingCourier11/10/2020 19:25
62919CPU4702103allocated10/13/2020 22:27
62919CPU4702103awaitingPickup10/13/2020 22:27
62919CPU4702103complete10/14/2020 0:29
62919CPU4702103delivered10/14/2020 0:29
62919CPU4702103delivered10/14/2020 0:32
62919CPU4702103dispatched10/13/2020 22:40
62919CPU4702103inProgress10/13/2020 22:27
62919CPU4702103inTransit10/13/2020 23:31
62919CPU4702103picked10/13/2020 23:31
62919CPU4702103pickedUp10/13/2020 23:31
62919CPU4702103sourcingCourier10/13/2020 22:27

 

I would like it to appear as below

CustomerIdDeliveryIdDocumentIdShortIdallocatedawaitingPickupcompletedeliveredinProgressinTransitpickedsourcingCourierPickedUp
2255CPU609617812/3/2020 20:0812/3/2020 20:0812/3/2020 22:5212/3/2020 22:5212/3/2020 20:08Null12/3/2020 22:5212/3/2020 20:08Null
22560CPU126519411/10/2020 19:2511/10/2020 19:2511/10/2020 23:3611/10/2020 23:3611/10/2020 19:2511/10/2020 22:1911/10/2020 22:1911/10/2020 19:2511/10/2020 22:19

 

Thank you very much.

 

 

 

 

1 ACCEPTED SOLUTION
sayaliredij
Super User
Super User

Hi,

 

You can use Pivot table transformation in the power query. 

Select column Status name and Status Time.

 

sayaliredij_0-1620071541253.png

Click on Pivot Column

sayaliredij_1-1620071568139.png

 Select Pivot table properties as follows

sayaliredij_2-1620071607971.png

 

You will get the following results

 

sayaliredij_3-1620071631753.png

 

Regards,

Sayali

 

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

 

 





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

Proud to be a Super User!




View solution in original post

6 REPLIES 6
CNENFRNL
Community Champion
Community Champion

Simply group rows by CustomerId/DeliveryId/DocumentId/ShortId and pivot the derived table; then it's done.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rdO9boMwEAfwV6mYI3F3BhN7zQswlCnKgIiVWqWADGlfv0YMYEB1jDoARuh3/rg/12tE0Smi1N7G65IXHATH7Gxfyrpuq3JQdztGillMQPBGIOEc3U5/yp9SD7p55Lr6fHbBvGq/uloNyoUkU/LAu6r1tzLrFb8gdZOb9mFU3wevtrObPDBj3z5NZc/oYp9aGd+0HKYCSDxFkazbgzHCZFFIC3x206DAAssWzZSYZNxHnSYFWrdNgWvWzbspm14Pq4lJovDZucmHYNEdoDsJ2dsxH0uI8auYKiQZEAJbRwRinONJmdduIhJYYBkRS5OJgiThk05C/oky8lLdd+VQfeycVgI+7AYz8KScYC6s/SPQZ+dgHoLFurOv0J1gbnZ8+wU=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CustomerId = _t, DeliveryId = _t, DocumentId = _t, ShortId = _t, StatusName = _t, StatusTime = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CustomerId", Int64.Type}, {"DeliveryId", Int64.Type}, {"DocumentId", Int64.Type}, {"ShortId", type text}, {"StatusName", type text}, {"StatusTime", type datetime}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"CustomerId", "DeliveryId", "DocumentId", "ShortId"}, {{"ar", each Table.Pivot(_, List.Distinct(#"Changed Type"[StatusName]), "StatusName", "StatusTime")}}),
    #"Expanded ar" = Table.ExpandTableColumn(#"Grouped Rows", "ar", {"allocated", "awaitingPickup", "complete", "delivered", "inProgress", "picked", "sourcingCourier", "inTransit", "pickedUp", "dispatched"}, {"allocated", "awaitingPickup", "complete", "delivered", "inProgress", "picked", "sourcingCourier", "inTransit", "pickedUp", "dispatched"})
in
    #"Expanded ar"

Screenshot 2021-05-03 215340.png

 

But to my knowledge, the original one-dimensional table functions well in PBI data model in most cases; such transformations sometimes are redundant.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Thank you @CNENFRNL  for your time. This proved to be too complex for me, still a novie in this, and instead went with pivot described below by @sayaliredij .

sayaliredij
Super User
Super User

Hi,

 

You can use Pivot table transformation in the power query. 

Select column Status name and Status Time.

 

sayaliredij_0-1620071541253.png

Click on Pivot Column

sayaliredij_1-1620071568139.png

 Select Pivot table properties as follows

sayaliredij_2-1620071607971.png

 

You will get the following results

 

sayaliredij_3-1620071631753.png

 

Regards,

Sayali

 

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

 

 





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

Proud to be a Super User!




We have an option in matrics table, its very easy to transpose the coloumns. no need of complex Pivot options. just a switch button would help to achive thisHighlightedHighlighted

 

So simple, but before your post it took me hours (!) to replace this function using measures. 

Thank you @sayaliredij . It worked just the way I had envisioned. 

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.