cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JvdSchelling
Frequent Visitor

Rename columns referencing column number rather than column name

How can I rename columns of a table when I do not know upfront what the column names of the table are?

So effectively I would like to reference the columns by index rather than by name.

 

Input:

 

 

Table(
{AnyColumnName1: "SampleText1", AnyColumnName2: 10, AnyColumnName3: true},
{AnyColumnName1: "SampleText2", AnyColumnName2: 20, AnyColumnName3: false},
{AnyColumnName1: "SampleText3", AnyColumnName2: 30, AnyColumnName3: false}
)

 

 

Desired output:

 

 

Table(
{Field1: "SampleText1", Field2: 10, Field3: true},
{Field1: "SampleText2", Field2: 20, Field3: false},
{Field1: "SampleText3", Field2: 30, Field3: false}
)

 

 

 

Thanks for your suggestions!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @JvdSchelling ,

I use that one for alternative shading in galleries, but it is indexing records in a collection or gallery (nothing to do with field names). The biggest issue is that you simply cannot rename column names dynamically (either the old or new name) - you have to "hard code" these values.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

View solution in original post

3 REPLIES 3
WarrenBelz
Super User
Super User

Hi @JvdSchelling ,

Firstly there is no "index" (order) of columns that is accessible as such and RenameColumns needs both the original column and new names to function (you cannot refer to them dynamically in this function)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Hi @WarrenBelz ,

Thanks for your fast and clear response!

I'm still wondering though: Can my goal be achieved with a workaround? E.g. I learned from @RandyHayes that you can add an index column to a collection with:

Clear(colValuesIndexed);
//Loop through the original table and add an index (Seq) column
ForAll(Sequence(CountRows(colValues)),
    Collect(colValuesIndexed,
        Patch(Last(FirstN(colValues, Value)), {Seq: Value})
    )
)

So perhaps a creative workaround along those lines is still achievable?

 

Btw, I do hope that the Microsoft developers will consider to implement an index based column reference because personally I believe it will greatly increase flexible and versatile applications.

 

Best regards,

Johan

Hi @JvdSchelling ,

I use that one for alternative shading in galleries, but it is indexing records in a collection or gallery (nothing to do with field names). The biggest issue is that you simply cannot rename column names dynamically (either the old or new name) - you have to "hard code" these values.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,299)