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

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
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...

 

 

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?

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
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (25,243)