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 / combining two collections
Power Apps
Answered

combining two collections

(0) ShareShare
ReportReport
Posted on by Microsoft Employee
ClearCollect(
 test1,
 Choices('HM InterviewStatus')
);

 

this turns an option set into a collection:

 

ClearCollect(
 test2,
 ForAll(
 test1,
 CountIf(hm_request_can_id, InterviewStatus = Value)
 )
);

 

this loops through that collection, and counts how many times each value shows up in hm_request_can_id

 

Is there a way to combine these two collections so that its 1 collection with 2 columns: status & count?

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @morall 

    Yes, but can you explain what hm_request_can_id is?  Is that a datasource?

     

    If so, then this formula would give you what you need:

    AddColumns(
     RenameColumns(Choices('HM InterviewStatus'), "Value", "status"),
     "count", CountRows(Filter(hm_request_can_id, InterviewStatus = status))
    )

     

    I hope this is helpful for you. 

  • morall Profile Picture
    Microsoft Employee on at

    @RandyHayes it is a collection.

     

     

    ClearCollect(
     hm_request_can_id,
     Sort(
     AddColumns(
     Filter(
     DataSource
     Candidate.ID in tessa_candidates,
     'Created On' > DateAdd(
     Now(),
     -90,
     Days
     )
     ),
     "custom_candidate_id",
     Candidate.ID
     ),
     'Created On',
     Descending
     )
    );

     

     

     

     

  • morall Profile Picture
    Microsoft Employee on at

    @RandyHayes 

     

    I'm getting an empty collection:

     

    ClearCollect(
     test3,
     AddColumns(
     RenameColumns(Choices('HM InterviewStatus'), "Value", "status"),
     "count", CountRows(Filter(hm_request_can_id, InterviewStatus=Status))
     )
    );

     

    I feel like I'm not doing the AddColumns(), the first parameter is expecting a datasource and I'm asking it to rename a column....

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @morall 

    RenameColumns is a datasource.  It returns a table of the Choices function.

     

    Oh sorry though, I didn't even notice - you are specifying a Datasource for Choices but no column to get choices from.  What Column do you want the Choices from?  You need to specify that.

  • morall Profile Picture
    Microsoft Employee on at

    @RandyHayes 

     

    Choices('HM Interested')

    is an option set 

     

    I'm trying to create a collection that has two columns:
    Column 1:

    Choices from option Set

     

    Column 2:

    Count how many times that option appears in the other data source

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @morall 

    Yes, I understood that.

    The formula I provided should give you what you want.  Since it is not, let's explore a little.

    You originally had a formula of:

    ClearCollect(
     test1,
     Choices('HM InterviewStatus')
    );

    When you had that, did test1 have values?  And specifically, was test1 a table with a single column called "Value"?

    I had assumed Value based on your second formula. 

  • morall Profile Picture
    Microsoft Employee on at

    @Randy 

     

    Yes, your intuition is correct. it returned a collection with 1 column that had the option set value. I can't quite figure out how to add a column to that 🙂 

     

    Screen Shot 2020-09-25 at 7.15.24 PM.png

  • morall Profile Picture
    Microsoft Employee on at
    ClearCollect(
     test3,
     AddColumns(
     RenameColumns(Choices('HM InterviewStatus'), "Value", "status"),
     "count", CountRows(Filter(hm_request_can_id, InterviewStatus=Status))
     )
    );

     

    this is what I see:

     

    Screen Shot 2020-09-25 at 7.18.19 PM.png

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @morall 

    Perfect - thank you for the details.

    So, let's start basic and build up.

    ClearCollect(
     test3,
     AddColumns(
     RenameColumns(Choices('HM InterviewStatus'), "Value", "status"),
     "count", 1)
     )
    );

    Using the above formula, you should have a two column collection called test3 that should have 2 columns - "status" and "count" each row will have a count of 1 with this formula.

     

    I do see a typo in my original formula, so try this then instead on the "full speed ahead" formula:

    ClearCollect(
     test3,
     AddColumns(
     RenameColumns(Choices('HM InterviewStatus'), "Value", "status"),
     "count", CountRows(Filter(hm_request_can_id, InterviewStatus=status))
     )
    );

    It was that I simply had Status instead of status.

     

    So, let's see what you get with formula 1 and then the second formula.

     

  • morall Profile Picture
    Microsoft Employee on at

    once again, you were spot on. the "1" worked and the updated formula worked.

     

    Thank you, this helped me understand the mechanics of working with collections! 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 356 Most Valuable Professional

#2
11manish Profile Picture

11manish 225 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 211

Last 30 days Overall leaderboard