cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AgoS401
Helper I
Helper I

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 

 

 

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?

 

 

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

Changes to Ideas Coming

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

Top Solution Authors
Top Kudoed Authors
Users online (4,042)