cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

RenameColumns not working as expected

I've found when patching data back into a source from a collection, it helps to make sure your collection and source don't have the same column names as PowerApps can't determine the correct scope for the columns.  Yes, it's nice and easy if you're just appending and you can collect straight back into the source, but patching is another story it seems.

 

Creating the collection from the source is also nice and easy with ClearCollect(Collection, Source) - so I figured I'd try use RenameColumns after the fact to differentiate my collected columns from my source columns.  That's when the weirdness started;

 

ClearCollect(StageTable, QTable);
ClearCollect(CollectQuestions, RenameColumns(StageTable, "Category", "CollectCat"),
RenameColumns(StageTable, "QID", "CollectQID"),
RenameColumns(StageTable, "Questions", "CollectQ"))

Here's the staging collection followed by the new collection;

StageTableStageTableNew Collection with...???New Collection with...???

So, I'm pretty sure it's supposed to rename new columns...What am I doing wrong here?

 

Kind regards,

 

R

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Meneghino
Community Champion
Community Champion

OK, I think this is what you are looking for:

 

ClearCollect(StageTable, QTable);
ClearCollect(CollectQuestions, RenameColumns(RenameColumns(RenameColumns(StageTable, "Questions", "CollectQ"), "QID", "CollectQID"), "Category", "CollectCat"))

Does it work?

View solution in original post

6 REPLIES 6
Meneghino
Community Champion
Community Champion

Hi @Anonymous

The result you show is what I would expect with the code you have shown.

Could you please be more specific about what you would expect?

Anonymous
Not applicable

I was expecting a new collection with data from the original source, but with different column names....

Whereas I seem to have added columns instead of just renaming them...

 

 

Meneghino
Community Champion
Community Champion

OK, I think this is what you are looking for:

 

ClearCollect(StageTable, QTable);
ClearCollect(CollectQuestions, RenameColumns(RenameColumns(RenameColumns(StageTable, "Questions", "CollectQ"), "QID", "CollectQID"), "Category", "CollectCat"))

Does it work?

View solution in original post

Anonymous
Not applicable

It did indeed - I would never have gotten there - thanks!

 

So i'm guessing you have to only have one update item for RenameColumns meaning you have to nest it - not sure I understand the logic though, any chance you can explain it to me?

Meneghino
Community Champion
Community Champion

With ClearCollect(A, B, C, D) you were collecting B then C then D in A.

The only reason to nest the RenameColumns is that for some reason which is unclear to me RenameColumns only accepts one column to be renamed at a time, so you have to nest three of them.  The function should be renamed RenameColumn or fixed to accept more than one column at a time.

Thanks again Meneghino, your answers are always on point. much appreciated.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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