Forum Discussion
mofu1401
Helper I
1 year agoHow to transform data
Hi all, I have some old data in this format, is there a way to transform the data? I tried but I can't seem to transform it to show that Jan to Apr belongs the next year, 2014. 7March....
- 1 year ago
mofu1401 Try this, transformed a single table:
let Source = Excel.Workbook(File.Contents("C:\Users\gdeck\Downloads\7March.xlsx"), null, true), Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Period", type text}, {"May", Int64.Type}, {"Jun", Int64.Type}, {"Jul", Int64.Type}, {"Aug", Int64.Type}, {"Sep", Int64.Type}, {"Oct", Int64.Type}, {"Nov", Int64.Type}, {"Dec", Int64.Type}, {"Jan", Int64.Type}, {"Feb", Int64.Type}, {"Mar", Int64.Type}, {"Apr", Int64.Type}, {"Total", Int64.Type}}), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Period"}, "Attribute", "Value"), #"Duplicated Column" = Table.DuplicateColumn(#"Unpivoted Other Columns", "Period", "Period - Copy"), #"Split Column by Delimiter" = Table.SplitColumn(#"Duplicated Column", "Period - Copy", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Period - Copy.1", "Period - Copy.2", "Period - Copy.3", "Period - Copy.4", "Period - Copy.5"}), #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Period - Copy.1", type text}, {"Period - Copy.2", Int64.Type}, {"Period - Copy.3", type text}, {"Period - Copy.4", type text}, {"Period - Copy.5", Int64.Type}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Period - Copy.1", "Period - Copy.3", "Period - Copy.4"}), #"Added Custom" = Table.AddColumn(#"Removed Columns", "Year", each if [Attribute] = "Jan" or [Attribute] = "Feb" or [Attribute] = "Mar" or [Attribute] = "Apr" then [#"Period - Copy.5"] else [#"Period - Copy.2"]), #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"Period - Copy.2", "Period - Copy.5"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"Attribute", "Month"}}) in #"Renamed Columns"
johnt75
Super User
1 year agoYou can make 2 reference copies of the table, choosing the columns from 1 year in 1 and from the second year in the other. Unpivot the columns and get the appropriate year from the Period column, then append the queries back together. See the attached.