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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

10 REPLIES 10
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

v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
ImkeF
Super User
Super User

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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