let
pathFolder = "C:\...\Magasins",
FolderFiles = Folder.Files(pathFolder),
FilterRemoveTempFiles = Table.SelectRows(FolderFiles, each not Text.StartsWith([Name], "~")),
fnExtractFileData = (excelBinary as binary) as record =>
let
SourceFeuil1 = Excel.Workbook(excelBinary){[Kind="Sheet", Name="Feuil1"]}[Data],
BufferData = Table.SelectRows(SourceFeuil1[[Column1], [Column2], [Column3], [Column4]], each List.NonNullCount(Record.ToList(_))>0),
TableMontants = Table.FromRecords(List.Transform(List.PositionOf(BufferData[Column1], "Catégorie", 2), each [Catégorie=BufferData[Column2]{_}, CA=BufferData[Column2]{_+1}, Bénéfice=BufferData[Column2]{_+2}])),
Result = [Magasin=BufferData[Column2]{0}, Lieu=BufferData[Column4]{0}, Adresse=BufferData[Column2]{1}, Téléphone=BufferData[Column4]{1}, GPS=BufferData[Column4]{2}, Montants=TableMontants]
in
Result,
ExtractFilesInfos = Table.TransformColumns(FilterRemoveTempFiles, {{"Content", fnExtractFileData, type record}}),
SelectColumnContent = Table.SelectColumns(ExtractFilesInfos,{"Content"}),
DevelopColumnContent = Table.ExpandRecordColumn(SelectColumnContent, "Content", {"Magasin", "Lieu", "Adresse", "Téléphone", "GPS", "Montants"}, {"Magasin", "Lieu", "Adresse", "Téléphone", "GPS", "Montants"}),
ChangeColumnsTypes = Value.ReplaceType(DevelopColumnContent, type table [Magasin=text, Lieu=text, Adresse=text, Téléphone=text, GPS=text, Montants=table])
in
ChangeColumnsTypes