Power Query Filter by Column Position not Name

programsam

Board Regular
Joined
Feb 10, 2016
Messages
123
Trying to filter by column position and not column name but am getting a circular reference error. Can anyone assist? Code below...

Excel Formula:
= Table.SelectRows(#"Promoted Headers", each (Table.ColumnNames(#"AASB"){0} <> null and Table.ColumnNames(#"AASB"){0} <> "AG" and Table.ColumnNames(#"AASB"){0} <> "GBM"))
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I can’t tell what is causing the circular ref from the code, but the way to solve this issue is to first create a dynamic list of column names, then select the position you want. I normally do this using the UI and a bit of M

add a new manual step
=Table.ColumnNames(PrevStep)

this should give the list of column names
=Table.ColumnNames(PrevStep){2}
this will give you column 3 name

keep this code, then manually rename column 3 from PrevStep (in my example)
after the UI writes the code, remove the hard code ref to the name of column 3 and replace with the code above (which is dynamic)
Table.ColumnNames(PrevStep){2}
 
Upvote 1
Solution
I can’t tell what is causing the circular ref from the code, but the way to solve this issue is to first create a dynamic list of column names, then select the position you want. I normally do this using the UI and a bit of M

add a new manual step
=Table.ColumnNames(PrevStep)

this should give the list of column names
=Table.ColumnNames(PrevStep){2}
this will give you column 3 name

keep this code, then manually rename column 3 from PrevStep (in my example)
after the UI writes the code, remove the hard code ref to the name of column 3 and replace with the code above (which is dynamic)
Table.ColumnNames(PrevStep){2}
Thanks Matt,

I actually had this code but didn't think to just rename by position before filtering. Appreciate it!
 
Upvote 0

Forum statistics

Threads
1,223,947
Messages
6,175,559
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top