Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
one_eon
Frequent Visitor

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:

DataFile Name
TableFile1.xlsx
TableFile2.xlsx
TableFile3.xlsx

 

I tried to add a calculated column with the formula:

 

Table.SelectColumns(
  [Data], 
  List.Select(Table.ColumnNames([Data]), each not List.IsEmpty(Table.Column([Data], _)))
)

 

 

The error i get is:
Expression.Error: We cannot apply field access to the type Text.

 

I appreciate any assistance.

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

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 {}.

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

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 {}.

Wow, that fixed it.  Thank you.  And also thanks for the tip about "List.IsEmpty".  I'm sure that would have been my next question.

I had tried declaring a variable with 'let' but that hadn't worked either.  I guess I have to learn more about when to use variables and when to use functions in power query, as I have a hard time telling the difference between the two.

Not all the tables successfully rendered, as a few of them have a "DataFormat.Error: Invalid cell value '#DIV/0!'." But I suspect that is due to something in the file itself.  I will try to replace the errors in power query and run it again.

 

Again, thank you.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.