Forum Discussion
Power Query - removing all columns with no values?
- Anonymous10 years ago
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'.
2. Select all of the table and click the ‘Unpivoted Columns’.
3. Choose the first Column and click ‘Removed duplicates’, then modify the query to remove the second column.
Modify:
Table.Distinct(#"Unpivoted Columns", {"Attribute"}) => Table.Distinct(#"Unpivoted Columns", {"Attribute"}) [Attribute]
4. Click on ‘fx’ to add a custom step:
Use Table.SelectCoulmns function to get the specify columns:
For more detail info, you could refer to below link:
Video_017 How to Remove Null Columns with Power Query?
Regards,
Xiaoxin Sheng
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))- mightycrown9 years agoFrequent Visitor
HI Imkef,
I d like to use this function. However it doesn't workThis 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 Custom1I put the function to FnRemoveEmptyColumns
Can you help
- ImkeF9 years agoCommunity Champion
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
- mightycrown9 years agoFrequent Visitor
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.
- Rockstar7 years agoNew Member
Thanks for this one! For those of us that are already working with unpivoted and repivoted data, this works quite nicely