October 5, 2010
Hi John,
Yes, you don't even need to check if there are more than 4 columns, just select the columns you want and then right click on a selected column header -> Remove other columns
Regards
Phil
.
July 17, 2018
Hi Phil delete was probably the wrong action to include, as a follow up question how about the opposite.
If there are 6 columns do x if there are > 6 do y or if 4 columns do z
Basically I want to merge every two columns after the first two so 3+4 5+6 the files are pdfs and I have no control over how many columns it might have so at the moment it errors out if 5 and 6 are missing and there is always a final total column so an odd number and I delete that final column using your suggestion.
John
October 5, 2010
Hi John,
See attached file - This code merges pairs of columns as you describe : 3+4, 5+6 etc and will work for any number of columns providing it's an odd number as you said the last col will always be a total. It also removes the last column regardless of how many columns there are in the table.
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Names = Table.ColumnNames(Source),
MergedCols = List.Generate(
() => [x = Source, y = 2 ],
each [y] < List.Count(Names),
each [x = Table.CombineColumns([x], {Names{[y]}, Names{[y]+1}}, Combiner.CombineTextByDelimiter("", QuoteStyle.None), "Merged"&Text.From(y)), y = [y] + 2],
each [x]
),
MergedTable = MergedCols{List.Count(MergedCols)-1},
#"Removed Columns" = Table.RemoveColumns( MergedTable, Table.ColumnNames(MergedTable){List.Count( Table.ColumnNames(MergedTable)) -1})
in
#"Removed Columns"
Regards
Phil
1 Guest(s)