Forum Discussion

eWise's avatar
eWise
Icon for Helper II rankHelper II
5 years ago
Solved

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.

 

 

 

 

  • Hi,

     

    You can use Pivot table transformation in the power query. 

    Select column Status name and Status Time.

     

    Click on Pivot Column

     Select Pivot table properties as follows

     

    You will get the following results

     

     

    Regards,

    Sayali

     

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

     

     

6 Replies

  • Hi,

     

    You can use Pivot table transformation in the power query. 

    Select column Status name and Status Time.

     

    Click on Pivot Column

     Select Pivot table properties as follows

     

    You will get the following results

     

     

    Regards,

    Sayali

     

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

     

     

    • Prabhakarandev's avatar
      Prabhakarandev
      Regular Visitor

      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 thisHighlighted

       

      • Marta987's avatar
        Marta987
        New Member

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

  • CNENFRNL's avatar
    CNENFRNL
    Icon for Community Champion rankCommunity 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"

     

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

    • eWise's avatar
      eWise
      Icon for Helper II rankHelper II

      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 .