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 / Need help with Collect...
Power Apps
Answered

Need help with Collections

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

In a screen there are 10 questions, and user will select, Yes or No radio buttons. Upon clicking on submit button, coverages associated to the questions should be shown in the next screen based on configuration table.

Coverages are based on scenarios like, show Coverage4 if Q1 is Yes and Q2 is No. So created a configuration table accordingly like below:

Configuration table:

SCN-1Q1YesCov4
SCN-1Q2NoCov4
SCN-2Q2YesCov5
SCN-2Q3NoCov5
SCN-3Q3YesCov6
SCN-4Q4YesCov7
SCN-4Q5YesCov7

 

Implementation: On App Start, created a collection to hold the configuration table.

ClearCollect(configTable, ConfigurationTables);
ClearCollect(uniqueScenariosColl, Distinct(configTable,Scenarios));

 

uniqueScenarioColl = ["SCN-1","SCN-2","SCN-3",...........]

Now on click on submit button, saved user's response in collection like below:

userResponseCol = [{q="Q01",r="Yes"},{q="Q02",r="No"},{q="Q03",r="No"}]

 

I am not able to merge the below two ForAll conditions. logic is loop all scenarios, get first scenario conditions, here Q1 is Yes and Q2 is No, check if two records are in userResponseColl, only then add the Cov4 to the finalCoverageCollection, then check second scenario and go on..

 

ForAll(uniqueScenariosColl,Collect(scenarioColl,Filter(configTable,Scenarios=Value)));

 

ForAll(scenarioColl,ForAll(userResponseCol, If(ThisRecord.q= QuestionId And ThisRecord.r = Response,Collect(matchColl,CoverageId))));
If(CountRows(matchColl) = CountRows(scenarioColl),Collect(finalCoverageCollection,matchColl));

Clear(scenarioColl); Clear(matchColl);

 

Appreciate your help here. 

 

Categories:
I have the same question (0)
  • EddieE Profile Picture
    4,650 Moderator on at

    @Anonymous 

    Try using As to separate off your 2 collection in the second ForAll(), ie

     

    ForAll(

        scenarioColl As scCol,

           ForAll(

               userResponseCol As urCol, 

    ….

    )

     

    Then use scCol and urCol to reference the different collections. Using ThisRecord doesn’t usually work inside 2 x ForAll statements 

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thanks for the response. Whatever you have mentioned i.e., second ForAll is working fine, what i am looking for  - include the second ForAll within first ForAll and make it work.

    First loop: ForAll(uniqueScenariosColl,Collect(scenarioColl,Filter(configTable,Scenarios=Value)));

    Second ForAll: ForAll(scenarioColl,ForAll(userResponseCol, If(ThisRecord.q= QuestionId And ThisRecord.r = Response,Collect(matchColl,CoverageId))));

     

    merge these two and also need to include below two statements in second ForAll.

    If(CountRows(matchColl) = CountRows(scenarioColl),Collect(finalCoverageCollection,matchColl));

    Clear(scenarioColl); Clear(matchColl);

  • Verified answer
    EddieE Profile Picture
    4,650 Moderator on at

    @Anonymous 

    Here a method to get what you want - ie Coverage values - but you may need to adjust it slightly?

     

    App OnStart

    // App OnStart
    
    ClearCollect(
     configTable,
     {Scenario: "SCN-1",	Question: "Q1",	QResponse: "Yes", Coverage: "Cov4"},
     {Scenario: "SCN-1",	Question: "Q2",	QResponse: "No", Coverage: "Cov4"},
     {Scenario: "SCN-2",	Question: "Q2",	QResponse: "Yes", Coverage: "Cov5"},
     {Scenario: "SCN-2",	Question: "Q3",	QResponse: "No", Coverage: "Cov5"},
     {Scenario: "SCN-3",	Question: "Q3",	QResponse: "Yes", Coverage: "Cov6"},
     {Scenario: "SCN-4",	Question: "Q4",	QResponse: "Yes", Coverage: "Cov7"},
     {Scenario: "SCN-4",	Question: "Q5",	QResponse: "Yes", Coverage: "Cov7"}
    );
    
    // responses table with 2 extra columns
    ClearCollect(
     responsesInitial,
     AddColumns(configTable, "CoverageResponse", "", "ShowValue", "" )
    );

    I've added two columns to the original configTable in a new collection that can be used below

     

    Question gallery

    Distinct(configTable, Question).Result

     

    Yes/No Radio button OnChange

    UpdateIf(
     responsesInitial,
     Question = ThisItem.Result , 
     {
     CoverageResponse: rd5.Selected.Value 
     }
    );

     

    Submit button

    ClearCollect(
     userResponseCol,
     ForAll(
     responsesInitial,
     {
     Scenario: Scenario,
     Question: Question,	
     QResponse: QResponse, 
     Coverage: Coverage,
     CoverageResponse: CoverageResponse,
     ShowValue: If(QResponse = CoverageResponse, 1,0)
     }
     )
    );
    
    
    Clear(finalCoverageCollection);
    ForAll(
     Distinct(userResponseCol, Scenario) As ds,
     If(
     CountRows( Filter(userResponseCol, Scenario = ds.Result)) = Sum( Filter(userResponseCol, Scenario = ds.Result),ShowValue ),
     Collect(
     finalCoverageCollection, 
     LookUp( userResponseCol, Scenario = ds.Result, Coverage)
     )
     )
    )

     

    Examples of use using your data above

    EddieE_0-1656914527090.pngEddieE_1-1656914584698.png

    Hopefully this makes sense and gets you what you need?

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thank you @EddieE  for the response. I solved my issue by merging the loops like said above,  and really liked your approach as well. Appreciate your help.

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 345 Most Valuable Professional

#2
11manish Profile Picture

11manish 207 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 177

Last 30 days Overall leaderboard