Forum

Combine sheets only...
 
Notifications
Clear all

Combine sheets only include columns with data

3 Posts
2 Users
0 Reactions
198 Views
(@baxbax)
Posts: 125
Estimable Member
Topic starter
 

Hi

I have been asked to combine the data from the sheets in what I can only describe as the worst workbook ever. The file contains 20+ sheets. Each sheet currently has around 1600 columns of data (It is a daily file going back to 2017). There are around 300 rows in each sheet. The data is not in tables or named ranges. Before you say update the format and start again I can't this is not my file and the person who it belongs to will not entertain any changes!

So the issue I am having is two fold. Firstly the number of columns with actual data increases each week as new dates are added. Secondly there are some elements in some of the sheets that mean if you go end --> Home to go to the end of the used range it goes to a column that is around column 16,000 even though there is no actual data in that area. This means that when you try and combine the sheets it includes all of these empty columns in the data.

What would be the best approach to combining these sheets. Is there a way in the query that I can only select columns with actual text/numeric data in them? When new data is added how can I pick up the new columns?

I am off for a lie down as this file is the worst thing I have every seen 🙂

All help greatly received.

 

Bax

 
Posted : 24/10/2022 7:32 am
Riny van Eekelen
(@riny)
Posts: 1201
Member Moderator
 

Hi,

You could create a function that removes all empty columns for you. A similar question came up several years ago in the Microsoft Tech Community.

The function looks like this:

(Source as table) as table =>

let

    RemoveEmptyColumns = Table.SelectColumns(
        Source,
        List.Select(
            Table.ColumnNames(Source),
            each List.NonNullCount(Table.Column(Source, _)) <> 0
        )
    )
in
    RemoveEmptyColumns

 

https://techcommunity.microsoft.com/t5/excel/power-query-remove-empty-columns/m-p/1331494

Tested it myself. It works though it may take a while when you are dealing with 16000 columns.

Riny

 
Posted : 24/10/2022 10:03 am
(@baxbax)
Posts: 125
Estimable Member
Topic starter
 

Thanks Riny. I will check this out.

 
Posted : 25/10/2022 8:43 am
Share: