web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Clearcollect: Initial ...
Power Apps
Unanswered

Clearcollect: Initial data load from a Dataverse data source table. Second data load from a Collection

(0) ShareShare
ReportReport
Posted on by 27

I am working with a collection connected to a gallery. Initially, I load data from a Dataverse table (GrpAAA_EntityData) into the collection (ColNodes):

 

 

ClearCollect (ColNodes, ShowColumns ( GrpAAA_EntityData, _JAHP_Name, _JAHP_EntityId, _JAHP_InstanceId, _JAHP_EntityInstanceKey )); 

 

 

Later I want to reload to the same collection (ColNodes), but this time with data coming from another collection (ColTemp) that is created like this:

 

 

ClearCollect (ColTemp, ShowColumns(ColParentNodes, _JAHP_Name, _JAHP_LnkParentNodeEntity, _JAHP_LnkParentNodeInstance, _JAHP_LnkParentNodeKey)); 

 

 

As you can see, both data sources are similar and compatible in terms of number of columns, but the column names are different.

 

Therefore as part of the new data load, I try to change the column names of the ColTemp collection before I load the data:

 

 

ClearCollect(ColNodes,
 RenameColumns(ColTemp,
 _JAHP_Name, _JAHP_Name,
 cr406__jahp_lnkparentnodeentity, _JAHP_EntityId,
 cr406__jahp_lnkparentnodeinstance, _JAHP_InstanceId,
 cr406__jahp_lnkparentnodekey, _JAHP_EntityInstanceKey
 )
 ); 

 

 

What I end up with is a ColNodes collection with 8 columns and only with data in the first 4 columns originating from the 'RenameColumns' function...

The outcome of all of this is also, that the display of the new data in the connected gallery goes wrong, because the labels in the gallery are connected to the columns without data...

So I see two challenges here...: In order for me to rename the column names of the ColTemp collection, I had to use the full display name with the prefix coming from the environment, and still the outcome is that the resulting collection is incompatible with the column names of the ColNodes collection so data is collected in 4 new columns adding to a new version of the ColNodes collection, now with 8 columns.

Can someone explain what is happening here, and what can I do to solve this challenge ?

Thanks in advance.

Categories:
I have the same question (0)
  • Sam33 Profile Picture
    13 on at

    It appears that the issue you’re facing is due to the RenameColumns function creating a new collection with renamed columns, rather than renaming the columns in the existing collection. When you use ClearCollect with RenameColumns, it doesn’t overwrite the existing columns but adds the renamed columns to the collection, resulting in a collection with both the old and new column names

     

    Here’s a revised approach to ensure that the columns are correctly renamed and the existing data is replaced:

    ClearCollect(
     ColNodes,
     RenameColumns(
     ShowColumns(
     ColTemp,
     "_JAHP_Name",
     "cr406__jahp_lnkparentnodeentity",
     "cr406__jahp_lnkparentnodeinstance",
     "cr406__jahp_lnkparentnodekey"
     ),
     "cr406__jahp_lnkparentnodeentity", "_JAHP_EntityId",
     "cr406__jahp_lnkparentnodeinstance", "_JAHP_InstanceId",
     "cr406__jahp_lnkparentnodekey", "_JAHP_EntityInstanceKey"
     )
    );

    This code will create a new collection ColNodes with the columns from ColTemp renamed to match the original GrpAAA_EntityData table. Make sure that the column names used in ShowColumns for ColTemp match the actual column names in ColTemp.

     

    If you continue to experience issues, you might want to consider using AddColumns and DropColumns to manipulate the collection structure.

  • JakobAnkerHanse Profile Picture
    27 on at

    Thanks... I tried it, but the result is still the same...: ColNodes is created with 8 columns:

     

    JakobAnkerHanse_0-1719493395439.png

     

  • JakobAnkerHanse Profile Picture
    27 on at

    Now I got it to work with the following formula...:

     

    ClearCollect(
     ColNodes,
     RenameColumns(
     ShowColumns(
     ColTemp,
     _JAHP_Name,
     cr406__jahp_lnkparentnodeentity,
     cr406__jahp_lnkparentnodeinstance,
     cr406__jahp_lnkparentnodekey
     ),
     _JAHP_Name, cr406__jahp_name,
     cr406__jahp_lnkparentnodeentity, cr406__jahp_entityid,
     cr406__jahp_lnkparentnodeinstance, cr406__jahp_instanceid,
     cr406__jahp_lnkparentnodekey, cr406__jahp_entityinstancekey
     )
    );
  • Sam33 Profile Picture
    13 on at

    Try adding a Clear(ColNodes); 

    so your code will look like this:

     

    Clear(ColNodes); // Clear the existing collection
    Collect(
     ColNodes,
     AddColumns(
     RenameColumns(
     DropColumns(
     ColTemp,
     "_JAHP_LnkParentNodeEntity",
     "_JAHP_LnkParentNodeInstance",
     "_JAHP_LnkParentNodeKey"
     ),
     "cr406__jahp_lnkparentnodeentity", "_JAHP_EntityId",
     "cr406__jahp_lnkparentnodeinstance", "_JAHP_InstanceId",
     "cr406__jahp_lnkparentnodekey", "_JAHP_EntityInstanceKey"
     ),
     "_JAHP_Name", "_JAHP_Name"
     )
    );
  • JakobAnkerHanse Profile Picture
    27 on at

    Thank you, Sam; you got me on track 🙂

     

    Now I will play around some more, and see if I can simplify things...

     

    Two immediate observations...: 

     

    1) It doesn't work for me, if I use "quotation marks" around the column names...

    2) This prefix (cr406_), coming from the environment, that is prepended to the column names really seem to complicate things... In some cases, you must use the full (lower case) display name with the prefix as part of column references... In other cases it is good enough to just use the simple short name (with correct case) of columns when referencing the columns...

    Can someone elaborate about this ?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 762

#2
11manish Profile Picture

11manish 640

#3
Valantis Profile Picture

Valantis 548

Last 30 days Overall leaderboard