I’ve been combining sheets out of a folder using power query. Problem I have is some sheets have 4 columns and some 3.
The first two columns in a couple of sheets are duplicates are I’m to only consider the second column in this case as it holds the correct data.
I tried deleting the first column but this also deletes for the ones with the correct format.
I’ve tried amending it from the sample file but not sure the best approach in this case. Any help appreciated, be gentle pls I’m new to all this.
Additional context below:
Expected table format:
[name] [address] [type]
Problematic table format:
[name] [name] [address] [type]
some have 4 columns, some have 3, I’m wanting to delete the first column on the tables with 4 without affecting the ones with 3 columns when combining them
Output (2)
let
Source = Folder Files("source"),
#"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <› true),
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1",
"Transform File", each #"Transform File" ([Content])),
#"Renamed Columns1" = Table.RenameColumns (#"Invoke Custom Function1", {"Name", "Source Name"}),
#"Removed Other Columns1" = Table.SelectColumns (#"Renamed
Columns1", {"Source.Name", "Transform File"}),
#"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Table.ColumnNames(#"Transform File"(#"
in
#"Expanded Table Column1"
Different approach:
let
//You don't provide sufficient information to code, but somehow you should create a list of tables to process
#"List of Files" = {Table1, Table2},
#"Final colNames" = {"Name","Address","Type"},
//Then combine the files removing the first column from tables with four columns
#"Combine Files" = List.Accumulate(
#"List of Files",
#table({},{}),
(s,c) => let
colNames = Table.ColumnNames(c),
count = List.Count(colNames),
t = if count = 4
then Table.RemoveColumns(c,colNames{0})
else c,
renames = if count=4
then Table.RenameColumns(t,List.Zip({List.Skip(colNames),#"Final colNames"}))
else Table.RenameColumns(t, List.Zip({colNames,#"Final colNames"}))
in Table.Combine({s, renames}))
in
#"Combine Files"