Import of a Variable Number of Columns

Hi

I import a range from a workbook. In some files the range has 17 Columns some 19 and some only 8.

I do not know what keywords I should use to search for the Solution on the Forum so that the import is dynamic - any suggestions.

Thank You

Allister

BTW my current code is

let
Source = Excel.Workbook(File.Contents(pe_FilePath_LY_Workbook), null, true),
r_xPPE_DefinedName = Source{[Item=“r_xPPE”,Kind=“DefinedName”]}[Data],
#“Removed Other Columns” = Table.SelectColumns(r_xPPE_DefinedName,{“Column3”, “Column5”, “Column7”, “Column9”, “Column11”, “Column13”, “Column15”, “Column17”, “Column19”}),
#“Reordered Columns” = Table.ReorderColumns(#“Removed Other Columns”,{“Column3”, “Column19”, “Column5”, “Column7”, “Column9”, “Column11”, “Column13”, “Column15”, “Column17”}),
#“Removed Top Rows” = Table.Skip(#“Reordered Columns”,2),
#“Promoted Headers” = Table.PromoteHeaders(#“Removed Top Rows”, [PromoteAllScalars=true]),
#“Unpivoted Other Columns” = Table.UnpivotOtherColumns(#“Promoted Headers”, {“Column1”, “Column2”}, “Attribute”, “Value”),
#“Renamed Columns” = Table.RenameColumns(#“Unpivoted Other Columns”,{{“Column1”, “Line Name Maj”}, {“Column2”, “Line Name Min”}, {“Attribute”, “FA Group”}}),
#“Filtered Rows2” = Table.SelectRows(#“Renamed Columns”, each Text.Contains([Line Name Min], “TY_”)),
#“Replaced Value” = Table.ReplaceValue(#“Filtered Rows2”,“TY”,“LY”,Replacer.ReplaceText,{“Line Name Min”}),
#“Duplicated Column” = Table.DuplicateColumn(#“Replaced Value”, “Line Name Min”, “Line Name Min - Copy”),
#“Added Conditional Column” = Table.AddColumn(#“Duplicated Column”, “Ledger”, each if Text.Contains([#“Line Name Min - Copy”], “ost”) then “Cost” else if Text.Contains([Line Name Min], “epr”) then “Depreciation” else if Text.Contains([Line Name Min], “arry”) then “Carrying Value” else 99),
#“Filtered Rows1” = Table.SelectRows(#“Added Conditional Column”, each ([Line Name Min] <> null) and ([Ledger] <> “Carrying Value”))
in
#“Filtered Rows1”

Hi @AllisterB,

Will need more to go on here, are you trying to append those tables or what is the actual issue you are trying to solve? You are performing key-match lookup so you should always get all data…

The columns that you remove, do they always have the same name in all workbooks? You can create a list and just add columns name to them and use it remove columns that match.

Hi @AllisterB, the code you posted shows 2 issues you could avoid to solve the problem. Btw, your solution to Disable Peek was interesting. :blush:

Hi @AllisterB, did the response provided by the experts help in solving your query? If not, how far did you get and what kind of help you need further? If yes, kindly mark as solution the answer that solved your query. Thanks!

Hi @AllisterB, due to inactivity, a response on this post has been tagged as “Solution”. If you have a follow question or concern related to this topic, please remove the Solution tag first by clicking the three dots beside Reply and then untick the check box.