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?

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
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (1,887)