SOLVED

power query remove empty columns

Iron Contributor

hi,

Can anyone tell me if it is possible to "remove empty columns" as it is to "remove empty rows"?

Thanks Juan

2 Replies
best response confirmed by juan jimenez (Iron Contributor)
Solution

@juan jimenez 

If automatically that could be function like

(Source as table) as table =>

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

@juan jimenez 

Depending on your table size, you could transpose the table in PQ, then filter out blank rows on a column, then transpose back.

 

To keep the column headers though, you should demote the headers before you transpose, then promote them after you transpose the table back.

1 best response

Accepted Solutions
best response confirmed by juan jimenez (Iron Contributor)
Solution

@juan jimenez 

If automatically that could be function like

(Source as table) as table =>

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

View solution in original post