Unpivot and Arrange the data in Sheet1

Thank you MarceBeug for your help..
No, you got it wrong.

This code replaces the table type of the table in #"Removed Columns" by the table type of table Part1.
A table type is the combination of the table properties: column names, column types and any table keys.

In this case, it is used to synchronize the column names and column types of the second part with those of the first part.
It doesn't affect any table content.
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
MarcelBeug
1- Did you use UI or typed in editor "Part1 = Table.TransformColumnNames(#"Removed Other Columns", each Text.Replace(_, "First ","")),"??
2- What does "_" mean here in "
each Text.Replace(_, "First ",""))"??
Actuallly it is not really unpivot, rather take a set of columns, take another set of columns and glue the 2 parts together.

More detail:

I renamed the columns in the first part (remove "First ") using function Table.TransformColumnNames, which is - I guess - not a well known function as it is never used in code that is generated from the Query Editor options.

I renamed the columns of the second part by simply replacing the table type (i.e. the column names, their types and any table keys) with the table typ from part 1.
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1418"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Bus Driver ID", Int64.Type}, {"Bus Driver Name", type text}, {"Mobile No. 1", Int64.Type}, {"Mobile No. 2", Int64.Type}, {"Bus No.", type text}, {"Bus Plate No.", Int64.Type}, {"Bus Type", type text}, {"Seats", Int64.Type}, {"First Trip ID", type text}, {"First School Name", type text}, {"Students Gender", type text}, {"First Bus Assistant ID", Int64.Type}, {"First Bus Assistant Name", type text}, {"First Bus Assistant Mobile", Int64.Type}, {"Second Trip ID", type text}, {"Second School Name", type text}, {"Students Gender2", type text}, {"Second Bus Assistant ID", Int64.Type}, {"Second Bus Assistant Name", type text}, {"Second Bus Assistant Mobile", Int64.Type}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"Bus Driver ID", "Bus Driver Name", "Mobile No. 1", "Mobile No. 2", "Bus No.", "Bus Plate No.", "Bus Type", "Seats", "First Trip ID", "First School Name", "Students Gender", "First Bus Assistant ID", "First Bus Assistant Name", "First Bus Assistant Mobile"}),
    Part1 = Table.TransformColumnNames(#"Removed Other Columns", each Text.Replace(_, "First ","")),

    // Notice that the next step proceeds again from step #"Changed Type:
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"First Trip ID", "First School Name", "Students Gender", "First Bus Assistant ID", "First Bus Assistant Name", "First Bus Assistant Mobile"}),
    Part2 = Value.ReplaceType(#"Removed Columns",Value.Type(Part1)),
    #"Parts Combined" = Part1 & Part2,
    #"Filtered Rows" = Table.SelectRows(#"Parts Combined", each ([Trip ID] <> null))
in
    #"Filtered Rows"
 
Upvote 0
3- Also explain "Part2 = Value.ReplaceType(#"Removed Columns",Value.Type(Part1))"
Shouldn't I do here "Part2 =
Table.TransformColumnNames(#"Removed Other Columns", each Text.Replace(_, "Second ",""))"
 
Upvote 0
1. Advanced Editor.
2. "_" refers to each individual current value. In general "_" is used in combination with each. In this case, the current values are the current column names.
3. I already explained in post #2 . Your alternative is also fine.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top