let
FilePath = Excel.CurrentWorkbook(){[Name="FilePath"]}[Content]{0}[Column1],
FileName = Excel.CurrentWorkbook(){[Name="FileName"]}[Content]{0}[Column1],
FilePathName = FilePath & FileName,
FileType = Excel.CurrentWorkbook(){[Name="FileType"]}[Content]{0}[Column1],
// THIS IS WHAT I'D LIKE TO DO, BUT IT DOESN'T WORK AS IS!!!
// START
If FileType = "csv" then
Source = Csv.Document(Web.Contents(FilePathName),[Delimiter=",", Columns=20, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
else
Source = Excel.Workbook(Web.Contents(FilePathName), null, true),
SourceTable = Table.SelectRows(Source, each [Kind] = "Sheet"){0}[Data],
#"Promoted Headers" = Table.PromoteHeaders(SourceTable, [PromoteAllScalars=true]),
// END
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{Table.ColumnNames(#"Promoted Headers"){0}, type date}, {Table.ColumnNames(#"Promoted Headers"){1}, type text}, {Table.ColumnNames(#"Promoted Headers"){2}, type text}, {Table.ColumnNames(#"Promoted Headers"){3}, type text}, {Table.ColumnNames(#"Promoted Headers"){4}, type text}, {Table.ColumnNames(#"Promoted Headers"){5}, type text}, {Table.ColumnNames(#"Promoted Headers"){6}, type text}, {Table.ColumnNames(#"Promoted Headers"){7}, type text}, {Table.ColumnNames(#"Promoted Headers"){8}, type text}, {Table.ColumnNames(#"Promoted Headers"){9}, type date}, {Table.ColumnNames(#"Promoted Headers"){10}, type text}, {Table.ColumnNames(#"Promoted Headers"){11}, type text}, {Table.ColumnNames(#"Promoted Headers"){12}, Int64.Type}, {Table.ColumnNames(#"Promoted Headers"){13}, type text}, {Table.ColumnNames(#"Promoted Headers"){14}, type text}, {Table.ColumnNames(#"Promoted Headers"){15}, type text}, {Table.ColumnNames(#"Promoted Headers"){16}, type text}, {Table.ColumnNames(#"Promoted Headers"){17}, type date}, {Table.ColumnNames(#"Promoted Headers"){18}, Int64.Type}, {Table.ColumnNames(#"Promoted Headers"){19}, type text}})
in
#"Changed Type"