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
Anonymous
Not applicable

How do I have Power BI intelligently delete blank columns?

I have a series of columns like this:

 

Original Data.png

 

I would like to intelligently delete any column (i.e. Class #4) that is completely blank without having to do so manually.

 

 

The only solution I could devise was unpivot the columns and do multiple group-bys before deleting all rows containing blanks. After that, however, I get stuck because I cannot pivot the unpivoted columns due to the "column names" containing duplicates.

 

Unpivoted Data.png

 

I even tried transposing, but that obviously just creates multiple columns for Class #3, which is NOT what I want unless there is any easy way to combine duplicate columns.

 

Any suggestions would be greatly appreciated. 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

 

You can use 'unpivot column' feature to transform your table, then use 'selected row' function to remove empty rows.

 

Full query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVtJRSkxJBZFlILZSrE60EogGCaSiiRRDVCrFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Class 1" = _t, #"Class 2" = _t, #"Class 3" = _t, #"Class 4" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Class 1", type text}, {"Class 2", type text}, {"Class 3", type text}, {"Class 4", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each ([Value] <> ""))
in
    #"Filtered Rows"

 

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

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

 

You can use 'unpivot column' feature to transform your table, then use 'selected row' function to remove empty rows.

 

Full query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVtJRSkxJBZFlILZSrE60EogGCaSiiRRDVCrFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Class 1" = _t, #"Class 2" = _t, #"Class 3" = _t, #"Class 4" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Class 1", type text}, {"Class 2", type text}, {"Class 3", type text}, {"Class 4", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each ([Value] <> ""))
in
    #"Filtered Rows"

 

Regards,

Xiaoxin Sheng

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

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.