Forum Discussion
eWise
5 years agoHelper II
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...
- 5 years ago
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.
CNENFRNL
5 years agoCommunity 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.
- eWise5 years agoHelper 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 .