Hello,
I have pivoted monthly forecast files stored in a SharePoint folder.
To unpivot the data I created the following PQ Function. However, I'm getting the following error message while trying to pass the files.
Can someone please guide me on how to overcome the issue?
I have pivoted monthly forecast files stored in a SharePoint folder.
To unpivot the data I created the following PQ Function. However, I'm getting the following error message while trying to pass the files.
Can someone please guide me on how to overcome the issue?
Power Query:
(MyTable as table) =>
let
// Filter out hidden files
#"Filtered Hidden Files1" = Table.SelectRows(MyTable, each [Attributes]?[Hidden]? <> true),
// Add a custom column to transform the binary content to a table
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File (2)", each Csv.Document(Binary.Decompress([Content], Compression.Deflate))),
// Rename columns for clarity
#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
// Remove unnecessary columns
#"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File (2)"}),
// Expand the table column to get the data
#"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File (2)", Table.ColumnNames(#"Transform File (2)"(#"Sample File (2)"))),
// Promote headers
#"Promoted Headers" = Table.PromoteHeaders(#"Expanded Table Column1", [PromoteAllScalars=true]),
// Get the first column name for renaming
CycleForecast = Table.ColumnNames(#"Promoted Headers"){0},
// Rename the first column to "Forecast_Month"
ForecastMonth = Table.RenameColumns(#"Promoted Headers", {{CycleForecast, "Forecast_Month"}}),
// Replace specific values in the "Forecast_Month" column
#"Replaced Value" = Table.ReplaceValue(ForecastMonth, "Monthly_Direct_Forecast_Hardware_", "", Replacer.ReplaceText, {"Forecast_Month"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value", ".csv", "", Replacer.ReplaceText, {"Forecast_Month"}),
// Unpivot the other columns
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Replaced Value1", {"Forecast_Month", "Business Area", "SKU No.", "PL"}, "Attribute", "Value"),
// Change the data types of specific columns
#"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Value", Int64.Type}, {"PL", type text}, {"SKU No.", type text}, {"Business Area", type text}})
in
#"Changed Type"