Forum Discussion
VGuruprasad2386
2 years agoRegular Visitor
Unpivots
Hi all, I have 35 questions for which I have a results same questions was rolled out last year I have results of that too, I have to compare and show the results to the management I tried unpi...
- 2 years ago
The code is very similar.
let Source = Excel.Workbook(File.Contents("C:\Users\aolson\Downloads\Sample raw_data.xlsx"), null, true), Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"Sl no", "Gender", "State", "Zone", "Department"}, "Question", "Value"), #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Year", each if Text.Contains([Question], "_") then "Last Year" else "This Year", type text), #"Extracted Text Before Delimiter" = Table.TransformColumns(#"Added Custom", {{"Question", each Text.BeforeDelimiter(_, "_"), type text}}), #"Pivoted Column" = Table.Pivot(#"Extracted Text Before Delimiter", List.Distinct(#"Extracted Text Before Delimiter"[Year]), "Year", "Value"), #"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",{{"This Year", Int64.Type}, {"Last Year", type number}, {"Sl no", Int64.Type}, {"Gender", type text}, {"State", type text}, {"Zone", type text}, {"Department", type text}, {"Question", type text}}) in #"Changed Type1"See attached file.
VGuruprasad2386
2 years agoRegular Visitor
Hi AlexisOlson,
Please find the raw data
https://docs.google.com/spreadsheets/d/1FR6JMDLNg_-CMGO8BhDpYjeYP7OcjiTMXVw7KUUrnfQ/edit?usp=sharing
AlexisOlson
Super User
2 years agoThe code is very similar.
let
Source = Excel.Workbook(File.Contents("C:\Users\aolson\Downloads\Sample raw_data.xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"Sl no", "Gender", "State", "Zone", "Department"}, "Question", "Value"),
#"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Year", each if Text.Contains([Question], "_") then "Last Year" else "This Year", type text),
#"Extracted Text Before Delimiter" = Table.TransformColumns(#"Added Custom", {{"Question", each Text.BeforeDelimiter(_, "_"), type text}}),
#"Pivoted Column" = Table.Pivot(#"Extracted Text Before Delimiter", List.Distinct(#"Extracted Text Before Delimiter"[Year]), "Year", "Value"),
#"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",{{"This Year", Int64.Type}, {"Last Year", type number}, {"Sl no", Int64.Type}, {"Gender", type text}, {"State", type text}, {"Zone", type text}, {"Department", type text}, {"Question", type text}})
in
#"Changed Type1"
See attached file.