none
Remove columns with wildcards RRS feed

  • Question

  • Hi,

    I have a datasheet that contains a lot of columns that I don't need, and these columns have a certain pattern in the naming. Instead of selecting them one by one, is there a way to add a line of code in the advanced editor to remove them all? For removing a single column, it produces this code:

    RemovedColumns = Table.RemoveColumns(Source,{"ColumnName"})

    Is there a way to use wildcards in that "ColumnName" to have multiple columns removed at once? I've tried the * and ? but that doesn't work.

    Thanks!


    - If a post answers your question, please click "Mark As Answer" on that post!

    Wednesday, April 16, 2014 8:05 AM

Answers

  • There isn't support for any kind of wild cards in the product today. If the pattern can be expressed in terms of "starts with" or other built-in functions, then you could generate the list programmatically. For instance, removing all columns starting with "V" could look like this:

    let
        Source = Table.FromRows({{"New York", 23, 51, 732}, {"Chicago", 25, 421, 23}, {"Los Angeles", 632, 22, 423}}, {"City", "Value 1", "Value 2", "Column 3"}),
        ColumnsToRemove = List.Select(Table.ColumnNames(Source), each Text.StartsWith(_, "V")),
        RemovedColumns = Table.RemoveColumns(Source, ColumnsToRemove)
    in
        RemovedColumns
    

    Wednesday, April 16, 2014 3:06 PM