Saturday, November 4, 2023

How to Dynamically remove unwanted Columns from a Table in Power Query

How to Remove Unwanted Columns Dynamically from a Table using Power Query
Scenario:
Suppose, we have a sample data table with unwanted columns as follows:

Now from this table, we want to remove the unwanted Columns like "Column-1", "Column_2", "null", "", "   ", "_" and "-".

We can achieve this Scenario, using the following Power Query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hco7CsAwDATRu6g2WKvIv7MY3/8aDpGrQLIwxRRvToFdLkmA7NkUev+7lR5WghXCarBKWAvWCOvBOmEj2PhnrsGgxOE4EGfH2adbGw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ProdId = _t, DateKey = _t, #"Column-1" = _t, Column_2 = _t, #"null" = _t, #"      " = _t, _ = _t, #"-" = _t]),

ColumnNames = Table.ColumnNames(Source),

RequiredCols
    List.Select(ColumnNames, each not Text.Contains(_ ,"Column") 
                and not List.Contains({"","_"," ","-","null"},Text.Trim(_))),

SelectCols = Table.SelectColumns(Source, RequiredCols)

in
    SelectCols

Result:

Thanks, TAMATAM

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. If you wish, please share your genuine Feedback or comments only related to this Blog Posts. It is my humble request that, please do not post any Spam comments or Advertising kind of comments, which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose we have a sample Sales data, which is stored with Monthly Snapsh...

Popular Posts from this Blog