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

Need help with Collections

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. 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@AgoS401 

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?

 

 

View solution in original post

4 REPLIES 4
EddieE
Super User
Super User

@AgoS401 

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 

 

 

AgoS401
Frequent Visitor

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

@AgoS401 

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?

 

 

AgoS401
Frequent Visitor

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.

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (2,969)