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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
igaca
Helper III
Helper III

Power Query - removing all columns with no values?

Hi,

 

Am wondering if someone has worked out a way to remove all columns containing no values (as in null / nothing...no zeroes) without checking each column in a query from its drop-down to check?  I would ideally like to apply this as a step.

 

Thanks ahead for any constructive input!

 

Igor

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi igaca,

 

Based on my understanding, you want to remove the null value column with power query, right?

If as I said, you could follow below steps:

 

1. Create a test table, and load it to power bi, click 'edit query'.

 Capture.PNG

 

2. Select all of the table and click the ‘Unpivoted Columns’.

 Capture2.PNG

 

Capture3.PNG

 3. Choose the first Column and click ‘Removed duplicates’, then modify the query to remove the second column.

Capture4.PNG

Modify:

Table.Distinct(#"Unpivoted Columns", {"Attribute"})  =>  Table.Distinct(#"Unpivoted Columns", {"Attribute"})  [Attribute]

Capture5.PNG

 

4. Click on ‘fx’ to add a custom step:

 Capture6.PNG

Use Table.SelectCoulmns function to get the specify columns:

 Capture7.PNG

 

For more detail info, you could refer to below link:

Video_017 How to Remove Null Columns with Power Query?

 

Regards,

Xiaoxin Sheng

View solution in original post

11 REPLIES 11
Anonymous
Not applicable

There's a much easier solution to this.

On the Home tab, select Choose Columns available under Manage Columns,

And filter out the null value columns

Anonymous
Not applicable

Hi igaca,

 

Based on my understanding, you want to remove the null value column with power query, right?

If as I said, you could follow below steps:

 

1. Create a test table, and load it to power bi, click 'edit query'.

 Capture.PNG

 

2. Select all of the table and click the ‘Unpivoted Columns’.

 Capture2.PNG

 

Capture3.PNG

 3. Choose the first Column and click ‘Removed duplicates’, then modify the query to remove the second column.

Capture4.PNG

Modify:

Table.Distinct(#"Unpivoted Columns", {"Attribute"})  =>  Table.Distinct(#"Unpivoted Columns", {"Attribute"})  [Attribute]

Capture5.PNG

 

4. Click on ‘fx’ to add a custom step:

 Capture6.PNG

Use Table.SelectCoulmns function to get the specify columns:

 Capture7.PNG

 

For more detail info, you could refer to below link:

Video_017 How to Remove Null Columns with Power Query?

 

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

If anyone is interested:
i solved the problem by using the editor and following steps:

#"Removed Top Rows" = Table.Skip(#"Changed Type",4),
    #"Removed Empty Columns" = Table.SelectColumns(#"Removed Top Rows", List.Select(Table.ColumnNames(#"Removed Top Rows"), each List.NonNullCount(Table.Column(#"Removed Top Rows", _)) > 0))
in
    #"Removed Empty Columns"

 

ImkeF
Community Champion
Community Champion

Hi Igor,

a quick & dirty-way is to unpivot your columns and then pivot-back. This will remove all columns with null only. But this can get slow for big tables.

In that case you can use this function instead:

 

(table) =>
 Table.SelectColumns(table, List.Select(Table.ColumnNames(table), each List.NonNullCount(Table.ToColumns(Table.SelectColumns(table, _)){0})>0))

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Thanks for this one! For those of us that are already working with unpivoted and repivoted data, this works quite nicely

HI Imkef,


I d like to use this function. However it doesn't work

This is my current query

let
Source = Oracle.Database("ORACLSQL", [HierarchicalNavigation=true]),
PO = Source{[Schema="PO"]}[Data],
PO_REQUISITION_HEADERS_ALL1 = PO{[Name="PO_REQUISITION_HEADERS_ALL"]}[Data],
Custom1 = FnRemoveEmptyColumns
in
Custom1

I put the function to FnRemoveEmptyColumns

 

Can you help

Pls try this:

 

let
Source = Oracle.Database("ORACLSQL", [HierarchicalNavigation=true]),
PO = Source{[Schema="PO"]}[Data],
PO_REQUISITION_HEADERS_ALL1 = PO{[Name="PO_REQUISITION_HEADERS_ALL"]}[Data],
Custom1 = FnRemoveEmptyColumns(PO_REQUISITION_HEADERS_ALL1)
in
Custom1

... you need to pass an argument to the function

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries


@ImkeF wrote:

Pls try this:

 

let
Source = Oracle.Database("ORACLSQL", [HierarchicalNavigation=true]),
PO = Source{[Schema="PO"]}[Data],
PO_REQUISITION_HEADERS_ALL1 = PO{[Name="PO_REQUISITION_HEADERS_ALL"]}[Data],
Custom1 = FnRemoveEmptyColumns(PO_REQUISITION_HEADERS_ALL1)
in
Custom1

... you need to pass an argument to the function

 


yep. thanks for the help. 

 

 

Any trick to exclude headers? 

 

Right now all the columns have a header, but I want eliminate these columns with no data in it.

Not sure if I understood you, but maybe this is what you'e looking for:

 

let
Source = Oracle.Database("ORACLSQL", [HierarchicalNavigation=true]),
PO = Source{[Schema="PO"]}[Data],
PO_REQUISITION_HEADERS_ALL1 = PO{[Name="PO_REQUISITION_HEADERS_ALL"]}[Data],
Custom1 = FnRemoveEmptyColumns(Table.PromoteHeaders(PO_REQUISITION_HEADERS_ALL1))
in
Custom1

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Tow
Frequent Visitor

Ok, during the query is fine.

But what, if I want them to be removed, only if the context of the user filtering reveals, that the columns got just null rows?

 

Is there an idea, how to handle that?

a_mixed_life
Resolver I
Resolver I

Are you wanting to filter it out during the query?

With my query when I didn't want 'null' or blank to be pulled from a specific column, I did this formula:

([Posted Source ID] <> null and [Posted Source ID] "")

*Posted Source ID was the column I was wanting to filter out

 

Hope that's what you're looking for.

Kris

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.