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!
Solved! Go to Solution.
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
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
User | Count |
---|---|
124 | |
87 | |
86 | |
75 | |
69 |
User | Count |
---|---|
214 | |
181 | |
139 | |
96 | |
83 |