none
Conditional Column removing in Power Query RRS feed

  • Question

  • Hi all,

    The API response is showing a field that appears only in certain conditions. This happens on server side so i do not have any way to mute this field. As such, i'd like Power Query to delete/mute this column if it appears inside the API response. This will resolve errors and tweaks inside the query each time i'm updating it.

    is there a way to achieve conditional column removing in Power Query ? Ex : If Column "X" appears then Remove Column "X" else nothing happens.

    Thank you

    Best,

    David

    Friday, September 30, 2016 9:03 AM

Answers

  • Hi David. Select the columns you care about, then use "Remove Other Columns". That way the extra column will be excluded if/when it appears.

    If for some reason there are other columns that can conditionally appear and you don't want those to be excluded, you can remove just a single conditional column using the following M:

    = if Table.HasColumns(PreviousStepName, "ColumnToRemove") then Table.RemoveColumns(PreviousStepName, "ColumnToRemove") else PreviousStepName

    Ehren


    Friday, September 30, 2016 5:46 PM
    Owner

All replies

  • Hi David. Select the columns you care about, then use "Remove Other Columns". That way the extra column will be excluded if/when it appears.

    If for some reason there are other columns that can conditionally appear and you don't want those to be excluded, you can remove just a single conditional column using the following M:

    = if Table.HasColumns(PreviousStepName, "ColumnToRemove") then Table.RemoveColumns(PreviousStepName, "ColumnToRemove") else PreviousStepName

    Ehren


    Friday, September 30, 2016 5:46 PM
    Owner
  • Thank you Ehren !

    You rock :-)

    Best,

    David

    Saturday, October 1, 2016 7:14 AM