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 / Collect and ungroup va...
Power Apps
Answered

Collect and ungroup values after a pre-existing row

(0) ShareShare
ReportReport
Posted on by 131

Using the QuickTask Template (Love it😁) provided I have tweaked a couple of things. I am collecting Planner plans by Teams Group as values but need a pre-existing row to be added to the beginning of the collection. 

Below is what I have:

 

ClearCollect(MyGroupandPlansGalleryItems, {groupname: "NotAGroup2", id: "NotAPlan2", title: "Create New Plan"});
Collect(MyGroupandPlansGalleryItems,If(!IsEmpty(MicrosoftTeams.GetAllTeams().value),ForAll(MicrosoftTeams.GetAllTeams().value, AddColumns(Planner.ListGroupPlans(id).value,"groupname",displayName))));
Clear(MyPlansGalleryItems);
ForAll(MyGroupandPlansGalleryItems,Collect(MyPlansGalleryItems,Value));

 

Which gathers the information correctly.

Problem is I just want to add the values after the pre-populated collection and not just the values. (Where the red arrow is below).

 

Capture.JPGCapture02.JPG

Categories:
I have the same question (0)
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @simondpalmer 

    Try this slight adjustment 

    ForAll(MyGroupandPlansGalleryItems,Collect(MyPlansGalleryItems,Value.groupname))
    
    // could also try
    ForAll(MyGroupandPlansGalleryItems,Collect(MyPlansGalleryItems,{GroupName: Value.groupname}))

     

  • simondpalmer Profile Picture
    131 on at

    Thank you for the reply. Unfortunately those don't work. The first idea created the collection I showed before. The second idea doesn't at all because it is not allowing me to use "groupname" for those values

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @simondpalmer 

    Sorry, I think I may have misunderstood you initial question. Are you wanting the first line of code to be a record inside the collection MyPlansGalleryItems?

     

    If so, it seems like you have the schema setup to simply use a Collect() function ie

    Collect(MyPlansGalleryItems, {groupname: "NotAGroup2", id: "NotAPlan2", title: "Create New Plan"});

     

    This will add it to the bottom, is that OK? If you are looking to use them as a first record in the list you could start them with underscore and use Sort(). If this record is to be column headings you could use RenameColumns on MyPlansGalleryItems?

     

     

     

  • simondpalmer Profile Picture
    131 on at

    Thanks, the "NotaPlan2" appears at the top of a combobox for the user to select when creating a new plan. Hence the need to have it as the first record. I guess i can use Sort function once I have added this custom record to the ungrouped values. Just would be nice to be able to Collect by index or something of that nature.

    However, I still cant add the custom record "NotaGroup2". It seems it is not allowing me to use the new column I added "Groupname" to add additional values to it. How so? Below is the code I have:

    ClearCollect(MyGroupandPlansGalleryItems,If(!IsEmpty(MicrosoftTeams.GetAllTeams().value),ForAll(MicrosoftTeams.GetAllTeams().value, AddColumns(Planner.ListGroupPlans(id).value,"Groupname",displayName))));
    Clear(MyPlansGalleryItems);
    ForAll(MyGroupandPlansGalleryItems,Collect(MyPlansGalleryItems,{Groupname: Value.groupname}));
    Collect(MyPlansGalleryItems, {Groupname: "NotAGroup2", id: "NotAPlan2", title: "Create New Plan"})

     

    To get it to work I have to rename "Groupname" to another name when I use the ForAll function, shown below:

    ForAll(MyGroupandPlansGalleryItems,Collect(MyPlansGalleryItems,{Groupname: Value.groupname}));

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @simondpalmer 

    Where you are using AddColumns() I think it is creating then removing that column name because you really are not using it.

     

    The schema of the collection MyPlansGalleryItems is:

    groupname | id | title

    ... so you should be using these headings to add a record/s, ie

    Collect(MyPlansGalleryItems, {groupname: "NotAGroup2", id: "NotAPlan2", title: "Create New Plan"})

     

    I actually think you could remove that AddColumns code and still get the same outcome?

  • Verified answer
    simondpalmer Profile Picture
    131 on at

    An update, you had it correct the issue I had was I had this code for a button AND on app start.. 😯🙃 I hadn't changed the latter yet so it was creating conflicting columns etc.

    The code I ended with for the button and on start is below:

    Collect(MyGroupandPlansGalleryItems,If(!IsEmpty(MicrosoftTeams.GetAllTeams().value),ForAll(MicrosoftTeams.GetAllTeams().value, AddColumns(Planner.ListGroupPlans(id).value,"groupname",displayName))));
    Clear(MyPlansGalleryItems);
    Collect(MyPlansGalleryItems, {groupname: "Click here", id: "NotAPlan2", title: "to create a new Plan"});
    ForAll(MyGroupandPlansGalleryItems,Collect(MyPlansGalleryItems,Value));

    Thank you for all your help @Anonymous 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @simondpalmer 

    Glad to see you got it sorted. It can certainly help sometimes to run stuff by others, just to get your thoughts straight 🙂 

     

    Just a note on your final code. You are starting it off with Collect and not ClearCollect. This will APPEND data to your collection for every button click. Not sure if you want that or not? You maybe wanting a ClearCollect() or Clear() to start off your code? Just a thought.

     

    All the best 🙂 

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
11manish Profile Picture

11manish 530

#2
WarrenBelz Profile Picture

WarrenBelz 459 Most Valuable Professional

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard