Forum Discussion
Anonymous
6 years agoNot applicable
Changing Dates on Columns
Hi! I've got a query to a file folder which contains Excel files with projected forecasts. Each file contains dates in columns and the values in rows. The problem is that the dates in the columns on...
- 6 years ago
Hi Anonymous ,
You can edit the Transform Sample File to handle it, like:
let Source = Excel.Workbook(Parameter1, null, true), Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]), #"Filled Down" = Table.FillDown(#"Promoted Headers",{"Quantity"}), #"Filtered Rows" = Table.SelectRows(#"Filled Down", each not Text.Contains([Quantity], "Total")), Row = Table.UnpivotOtherColumns(Table.Skip(Table.DemoteHeaders(Table.Skip(#"Filtered Rows",1)), 1), {"Column1", "Column2"}, "Attribute", "Value"), Header = Table.UnpivotOtherColumns(Table.Skip(Table.DemoteHeaders(Table.FirstN(#"Filtered Rows",1)),1), {"Column1", "Column2"}, "Attribute", "Value"), Merge = Table.NestedJoin( Table.UnpivotOtherColumns(Table.Skip(Table.DemoteHeaders(Table.Skip(#"Filtered Rows",1)), 1), {"Column1", "Column2"}, "Attribute", "Value"), "Attribute", Table.UnpivotOtherColumns(Table.Skip(Table.DemoteHeaders(Table.FirstN(#"Filtered Rows",1)),1), {"Column1", "Column2"}, "Attribute", "Value"), "Attribute", "Header", JoinKind.Inner ), #"Expanded Header" = Table.ExpandTableColumn(Merge, "Header", {"Value"}, {"Value.1"}), #"Removed Columns" = Table.RemoveColumns(#"Expanded Header",{"Attribute"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value.1", "Date"}, {"Column1", "Customer"}, {"Column2", "Name"}}), #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Customer", "Name", "Date", "Value"}), #"Changed Type" = Table.TransformColumnTypes(#"Reordered Columns",{{"Customer", type text}, {"Name", type text}, {"Date", type date}, {"Value", Int64.Type}}) in #"Changed Type"Check the steps Row and Header, the step Merge are skipping them and using only the code, you can delete the Row and Header once it's ok.
camargos88
Community Champion
6 years agoHi Anonymous ,
You can edit the Transform Sample File to handle it, like:
let
Source = Excel.Workbook(Parameter1, null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
#"Filled Down" = Table.FillDown(#"Promoted Headers",{"Quantity"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each not Text.Contains([Quantity], "Total")),
Row = Table.UnpivotOtherColumns(Table.Skip(Table.DemoteHeaders(Table.Skip(#"Filtered Rows",1)), 1), {"Column1", "Column2"}, "Attribute", "Value"),
Header = Table.UnpivotOtherColumns(Table.Skip(Table.DemoteHeaders(Table.FirstN(#"Filtered Rows",1)),1), {"Column1", "Column2"}, "Attribute", "Value"),
Merge = Table.NestedJoin(
Table.UnpivotOtherColumns(Table.Skip(Table.DemoteHeaders(Table.Skip(#"Filtered Rows",1)), 1), {"Column1", "Column2"}, "Attribute", "Value"),
"Attribute",
Table.UnpivotOtherColumns(Table.Skip(Table.DemoteHeaders(Table.FirstN(#"Filtered Rows",1)),1), {"Column1", "Column2"}, "Attribute", "Value"),
"Attribute",
"Header",
JoinKind.Inner
),
#"Expanded Header" = Table.ExpandTableColumn(Merge, "Header", {"Value"}, {"Value.1"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Header",{"Attribute"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value.1", "Date"}, {"Column1", "Customer"}, {"Column2", "Name"}}),
#"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Customer", "Name", "Date", "Value"}),
#"Changed Type" = Table.TransformColumnTypes(#"Reordered Columns",{{"Customer", type text}, {"Name", type text}, {"Date", type date}, {"Value", Int64.Type}})
in
#"Changed Type"
Check the steps Row and Header, the step Merge are skipping them and using only the code, you can delete the Row and Header once it's ok.
Anonymous
6 years agoNot applicable
Hi camargos88 ,
Thanks for your response! I'm not the best with M-code but I'll give it a shot and let you know how it goes.
Cheers,
Paddy