cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Birinder
Helper III
Helper III

How to select column based on their positions in a table through Power Query ?

Hi there,
I know how to get a single column by its position in a table:

 

= Table.SelectColumns(#"Promoted Headers",{Table.ColumnNames(#"Promoted Headers"){1}})

 

However, I am little helpless in the case where I don't know how to do the same for selecting more than one column.
Suppose I want to select columns from position 0 till position 5, How can I do that ?

Thanks and regards.

2 ACCEPTED SOLUTIONS
AntonioM
Super User
Super User

It's a little awkward but one thing you could do is 

= Table.SelectColumns(#"Promoted Headers",{Table.ColumnNames(#"Promoted Headers"){1}, Table.ColumnNames(#"Promoted Headers"){2}, Table.ColumnNames(#"Promoted Headers"){3}})

to get 1, 2 and 3

View solution in original post

Vijay_A_Verma
Super User
Super User

You will need to use List.Range property for this. Look below to see the columns from 0 till position 5

= Table.SelectColumns(#"Promoted Headers",List.Range(Table.ColumnNames(#"Promoted Headers"),0,6))

0 - Starting index is 0

6 - Total 6 columns i.e. position 5

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

You will need to use List.Range property for this. Look below to see the columns from 0 till position 5

= Table.SelectColumns(#"Promoted Headers",List.Range(Table.ColumnNames(#"Promoted Headers"),0,6))

0 - Starting index is 0

6 - Total 6 columns i.e. position 5

AntonioM
Super User
Super User

It's a little awkward but one thing you could do is 

= Table.SelectColumns(#"Promoted Headers",{Table.ColumnNames(#"Promoted Headers"){1}, Table.ColumnNames(#"Promoted Headers"){2}, Table.ColumnNames(#"Promoted Headers"){3}})

to get 1, 2 and 3

Helpful resources

Announcements
May 2023 update

Power BI May 2023 Update

Find out more about the May 2023 update.

Submit your Data Story

Data Stories Gallery

Share your Data Story with the Community in the Data Stories Gallery.

Top Solution Authors