let
pathPdf = "C:\...\ETAT DES FARs.pdf",
fnTableCleanColumn = (tableSource as table, columnName as text, minCar as number) as table =>
let
fnConcatenate = (listRawVals as list, minCar as number) as list =>
let
lstRaw = List.ReplaceValue(listRawVals, null, "", Replacer.ReplaceValue),
newVals = List.Transform({0 .. List.Count(lstRaw)-1}, each let nextVal = try lstRaw{_+1} otherwise "" in if Text.Length(lstRaw{_}) <= minCar then "" else if Text.Length(nextVal) > minCar then lstRaw{_} else lstRaw{_} & nextVal)
in
List.ReplaceValue(newVals, "", null, Replacer.ReplaceValue),
NewColumnValues = fnConcatenate(Table.ToList(Table.SelectColumns(tableSource, columnName)), minCar),
otherColumns = List.RemoveItems(Table.ColumnNames(tableSource), {columnName}),
ChangeColumnValues = Table.SelectColumns(Table.FromColumns(Table.ToColumns(Table.SelectColumns(tableSource, otherColumns)) & {NewColumnValues}, otherColumns & {columnName}), Table.ColumnNames(tableSource))
in
ChangeColumnValues,
SourcePdf = Pdf.Tables(File.Contents(pathPdf), [Implementation="1.3"]),
TableData = SourcePdf{[Id="Table001"]}[Data],
EntêtesPromus = Table.PromoteHeaders(TableData, [PromoteAllScalars=true]),
CleanProjectColumn = fnTableCleanColumn(EntêtesPromus, "Projet", 3),
CleanTacheColumn = fnTableCleanColumn(CleanProjectColumn, "Tache", 3),
LignesFiltrées = Table.SelectRows(CleanTacheColumn, each ([Compte] <> null)),
ColonnesFusionnéesDateMax = Table.CombineColumns(LignesFiltrées,{"Date max.", "Column7"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Date max..1"),
ColonnesFusionnéesDescription = Table.CombineColumns(ColonnesFusionnéesDateMax,{"Column9", "Description", "Column11", "Column12"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Description.1"),
ColonnesRenommées = Table.RenameColumns(ColonnesFusionnéesDescription,{{"Date max..1", "Date max."}, {"Description.1", "Description"}}),
ValeurRemplacée1 = Table.ReplaceValue(ColonnesRenommées,"",null,Replacer.ReplaceValue,{"Secteur", "Projet", "Tache"}),
RempliVersLeBas = Table.FillDown(ValeurRemplacée1,{"Secteur", "Projet", "Tache"}),
ValeurRemplacée2 = Table.ReplaceValue(RempliVersLeBas,".","",Replacer.ReplaceText,{"Mt Cde", "Mt Rec.", "Mt Facturé", "Montant FAR"}),
TypeModifié = Table.TransformColumnTypes(ValeurRemplacée2,{{"Mt Cde", Currency.Type}, {"Mt Rec.", Currency.Type}, {"Mt Facturé", Currency.Type}, {"Montant FAR", Currency.Type}, {"Date max.", type date}, {"Projet", type text}, {"Tache", type text}})
in
TypeModifié