cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
IveGotThePowa
Frequent Visitor

ForAll Collect duplicates

Hey guys,

 

I'm having a hard time with a ForAll and Collect formula.

 

The selections that I have are:

combobox1 = text1, text2

combobox2 = value1

 

Value email1 is linked to text1 and email2 is linked to text2.

 

Based on selections and dependencies in combo boxes, the final result should be like this:

column1column2column3
text1email1value1
text2email2value1

 

Instead it generates this:

column1column2column3
text1email1value1
text1email2value1
text2email1value1
text2email2value1
   

 

In this case the email1 should not get text2 and email2 should not get text1 information in column1. 

If I add value2 besides value1 to column 3, it will generate another set of 4 rows, but with the value2 on column3.

 

The formula looks like this: 

 

ForAll(combobox1.SelectedItems As a1,ForAll(combobox2.SelectedItems As a2,ForAll(combobox3.SelectedItems As a3,Collect(collection,{column1:a1.Title,column2:a2.Email,column3:a3.Title}))))

 

 

If you have any thoughts, it would be much appreciated. Thank you!

3 REPLIES 3
RandyHayes
Super User
Super User

@IveGotThePowa 

The biggest issue is that your formula has the ForAll backward. You are trying to use it like a ForLoop in some development language - which PowerApps is not.  ForAll is a function that returns a table of records based on your iteration table and record schema.

It is more efficient to use the function as intended and will provide better performance.

And in your case, you need to realize that each ForAll is creating a table.  AND, each ForAll takes a parameter (the second) to specify the record schema of the table returned from the ForAll...so, since you are not specifying it, it is creating (based on the flow of your formula) a Table with a column that has a table that has a column that has a table....so, you are getting a lot of table-in-table results and your results will be as you are seeing.

 

Can you describe a little more on the Items properties of Combobox 1, 2 and 3?  What you are trying to achieve is usually handled better within the Items property.  Also, if you have a DefaultSelectedItems property set on any of them, what are those.

I ask more because you mentioned combobox 1 and 2 in your post, but your formula references combobox3 and the relationship did not seem apparent.

 

_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes 

Yes, I am very aware of that. But I couldn't find another solution at the time.

 

The Items Properties of Combo Boxes are Share Point lists because I'm trying to avoid to hardcode them in the app. 

 

Basically I'm trying to create an access request app where the user can select the various combinations of options and then those selections are recorded to a Share Point list from where they are processed by an Approval flow.

 

So let's say I want to request a regional access for a dashboard. I select the dashboard that I want access to (let's say dash1), I select Regional access, then on the next combo box I am presented with RegionA, RegionB, RegionC (each of them has different approvers). I pick RegionA and RegionC. Now, I want this information to be patched to a Sharepoint List like this:

 

dashboardaccesstypeaccessnameapprover
dash1RegionalRegionAemail1
dash1RegionalRegionCemail2

  

Thank you!

@RandyHayes 

I think you would understand better what I'm trying to do from the post were it was recommended to me to use ForAll.

 

https://powerusers.microsoft.com/t5/Building-Power-Apps/Multiple-Combo-Boxes-different-combinations-...

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (3,058)