Forum Discussion
awsiya
2 years agoHelper I
How to use non first row as column header
Hi Below is a table where I want to utilise the column labeled "toprow," specifically when its value is 0, as the column header. I attempted to transpose the table, but it didn't yield the desired ...
- 2 years ago
let's say your sample survey data is in Excel table "Table1" then you can use Power Query to do some transformations steps as indicated in the M Code below. See the output.
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Sorted Rows" = Table.Sort(Source,{{"Toprow", Order.Ascending}}), #"Promoted Headers" = Table.PromoteHeaders(#"Sorted Rows", [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"0", Int64.Type}, {"Was food Hygienic", type text}, {"Overall Feedback", type text}, {"27/02/2024", type any}, {"Reception treated well", type text}, {"AirCon cool enough?", type text}}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"27/02/2024", "SurveyDate"}, {"0", "Toprow"}}), #"Changed Type with Locale" = Table.TransformColumnTypes(#"Renamed Columns", {{"SurveyDate", type date}}, "en-GB"), #"Reordered Columns" = Table.ReorderColumns(#"Changed Type with Locale",{"Toprow", "SurveyDate", "Was food Hygienic", "Overall Feedback", "Reception treated well", "AirCon cool enough?"}), #"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Toprow"}) in #"Removed Columns"Output:
SurveyDateWas food HygienicOverall FeedbackReception treated wellAirCon cool enough?
8/5/2022 some extend Bad No Yes 6/18/2022 Yes Good No No 5/9/2022 some extend Bad Yes Yes 6/25/2023 some extend Bad Yes Yes 5/18/2022 Yes Good Yes Yes 5/2/2024 Yes Excellent No No 1/13/2024 No Bad some extent Yes
amustafa
2 years agoSolution Sage
let's say your sample survey data is in Excel table "Table1" then you can use Power Query to do some transformations steps as indicated in the M Code below. See the output.
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Sorted Rows" = Table.Sort(Source,{{"Toprow", Order.Ascending}}),
#"Promoted Headers" = Table.PromoteHeaders(#"Sorted Rows", [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"0", Int64.Type}, {"Was food Hygienic", type text}, {"Overall Feedback", type text}, {"27/02/2024", type any}, {"Reception treated well", type text}, {"AirCon cool enough?", type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"27/02/2024", "SurveyDate"}, {"0", "Toprow"}}),
#"Changed Type with Locale" = Table.TransformColumnTypes(#"Renamed Columns", {{"SurveyDate", type date}}, "en-GB"),
#"Reordered Columns" = Table.ReorderColumns(#"Changed Type with Locale",{"Toprow", "SurveyDate", "Was food Hygienic", "Overall Feedback", "Reception treated well", "AirCon cool enough?"}),
#"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Toprow"})
in
#"Removed Columns"
Output:
SurveyDateWas food HygienicOverall FeedbackReception treated wellAirCon cool enough?
| 8/5/2022 | some extend | Bad | No | Yes |
| 6/18/2022 | Yes | Good | No | No |
| 5/9/2022 | some extend | Bad | Yes | Yes |
| 6/25/2023 | some extend | Bad | Yes | Yes |
| 5/18/2022 | Yes | Good | Yes | Yes |
| 5/2/2024 | Yes | Excellent | No | No |
| 1/13/2024 | No | Bad | some extent | Yes |