Forum Discussion

one_eon's avatar
one_eon
Frequent Visitor
4 years ago
Solved

Formula to Automatically Remove Blank Columns from a table

I have a folder of workbooks I am trying to import.  The data is messy.  For each of the workbooks I want to remove any blank columns before I combine the data. So my data looks like this: Data ...
  • AlexisOlson's avatar
    4 years ago

    This is a context reference issue. The problem here is that M thinks you want to take the [Data] column from the column name. You can clear this up by using a new name for your selection function.

    Table.SelectColumns(
      [Data], 
      List.Select(
          Table.ColumnNames([Data]),
          (colName) => List.NonNullCount(Table.Column([Data], colName)) > 0
      )
    )

    Note: List.IsEmpty returns FALSE for a column of null values since, e.g., {null, null} is not the same as {}.