cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
morall
Microsoft
Microsoft

combining two collections

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?

1 ACCEPTED SOLUTION

Accepted Solutions

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

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

11 REPLIES 11
RandyHayes
Super User III
Super User III

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

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

@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
    )
);

 

 

 

 

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

 

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

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

@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

 

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

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

@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

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

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

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,352)