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

Creating Collection which is a union of different collections

Hello Guys! 

 

Let me try explaining the scenario. We have three different collections based on certain conditions and we are trying to build a new collection which will be union of all the three collections which were based on different conditions. We were successful in building up the collection and it works when we try running the app from the development studio but does not work when we try it from the browser. Here is the code that I am using, am I going wrong somewhere?

 

ClearCollect(
    AssessmentByLocation,
    SortByColumns(
        Filter(
            'Assessment By Locations',
            Location.Location = LookUp(
                Contacts,
                Contact = ContactID
            ).Location.Location
        ),
        "mzk_order"
    )
);ClearCollect(
    AssessmentByRole,
    SortByColumns(
        Filter(
            'Assessment By Locations',
            Role.Role = LookUp(
                Contacts,
                Contact = ContactID
            ).'Role (mzk_Role)'.Role
        ),
        "mzk_order"
    )
);ClearCollect(
    AssessmentByLocationAndRole,
    SortByColumns(
        Filter(
            'Assessment By Locations',
            Location.Location = LookUp(
                Contacts,
                Contact = ContactID
            ).Location.Location && Role.Role = LookUp(
                Contacts,
                Contact = ContactID
            ).'Role (mzk_Role)'.Role
        ),
        "mzk_order"
    )
);

If(
    (CountRows(AssessmentByLocation) >= CountRows(AssessmentByRole)) && (CountRows(AssessmentByLocation) >= CountRows(AssessmentByLocationAndRole)),
    ClearCollect(
        FinalAssessments,
        AssessmentByLocation
    );
    ForAll(
        RenameColumns(
            AssessmentByRole,
            "mzk_Assessment",
            "AssessmentbyRoleID"
        ),
        If(
            IsEmpty(
                Filter(
                    FinalAssessments,
                    Assessment.Assessment = AssessmentbyRoleID.Assessment
                )
            ),
            Collect(
                FinalAssessments,
                LookUp(
                    AssessmentByRole,
                    Assessment.Assessment = AssessmentbyRoleID.Assessment
                )
            );
            ForAll(
                RenameColumns(
                    AssessmentByLocationAndRole,
                    "mzk_Assessment",
                    "AssessmentbyLRID"
                ),
                If(
                    IsEmpty(
                        Filter(
                            FinalAssessments,
                            Assessment.Assessment = AssessmentbyLRID.Assessment
                        )
                    ),
                    Collect(
                        FinalAssessments,
                        LookUp(
                            AssessmentByLocationAndRole,
                            Assessment.Assessment = AssessmentbyLRID.Assessment
                        )
                    )
                )
            )
        )
    ),
    If(
        CountRows(AssessmentByRole) >= CountRows(AssessmentByLocationAndRole),
        ClearCollect(
            FinalAssessments,
            AssessmentByRole
        );
        ForAll(
            RenameColumns(
                AssessmentByLocation,
                "mzk_Assessment",
                "AssessmentbyLocationID"
            ),
            If(
                IsEmpty(
                    Filter(
                        FinalAssessments,
                        Assessment.Assessment = AssessmentbyLocationID.Assessment
                    )
                ),
                Collect(
                    FinalAssessments,
                    LookUp(
                        AssessmentByLocation,
                        Assessment.Assessment = AssessmentbyLocationID.Assessment
                    )
                );
                ForAll(
                    RenameColumns(
                        AssessmentByLocationAndRole,
                        "mzk_Assessment",
                        "AssessmentbyLRID"
                    ),
                    If(
                        IsEmpty(
                            Filter(
                                FinalAssessments,
                                Assessment.Assessment = AssessmentbyLRID.Assessment
                            )
                        ),
                        Collect(
                            FinalAssessments,
                            LookUp(
                                AssessmentByLocationAndRole,
                                Assessment.Assessment = AssessmentbyLRID.Assessment
                            )
                        )
                    )
                )
            )
        ),
        ClearCollect(
            FinalAssessments,
            AssessmentByLocationAndRole
        );
        ForAll(
            RenameColumns(
                AssessmentByLocation,
                "mzk_Assessment",
                "AssessmentbyLocationID"
            ),
            If(
                IsEmpty(
                    Filter(
                        FinalAssessments,
                        Assessment.Assessment = AssessmentbyLocationID.Assessment
                    )
                ),
                Collect(
                    FinalAssessments,
                    LookUp(
                        AssessmentByLocation,
                        Assessment.Assessment = AssessmentbyLocationID.Assessment
                    )
                );
                ForAll(
                    RenameColumns(
                        AssessmentByRole,
                        "mzk_Assessment",
                        "AssessmentbyRoleID"
                    ),
                    If(
                        IsEmpty(
                            Filter(
                                FinalAssessments,
                                Assessment.Assessment = AssessmentbyRoleID.Assessment
                            )
                        ),
                        Collect(
                            FinalAssessments,
                            LookUp(
                                AssessmentByRole,
                                Assessment.Assessment = AssessmentbyRoleID.Assessment
                            )
                        )
                    )
                )
            )
        )
    )
);
ClearCollect(
    assessment,
    SortByColumns(FinalAssessments,
        "mzk_order"
    )
);

 

Spoiler
 

 

Any help is highly appreciated.

 

Thanks

Syed Danish

 

 

Spoiler
 

 

 

4 REPLIES 4
leyburn19
Memorable Member
Memorable Member

There may be an easier way aas yours seems very complex.  Can you indicate How many rows are in the table in the 'Assetr by location' table?

 

It would seem to me pending above that creating a simple collection with all records,  then do filters on that collection. 

 

Can you give more information on the objective and reason

v-xida-msft
Community Support
Community Support

Hi @syed_aalam001 ,

Do you mean that the formula you provided work well in your PowerApps Studio Designer, but not in published canvas app?

Where do you put your formula in your canvas app?

 

Based on the formula that you provided, I could not find any syntax error with it. Please consider modify your formula as below:

Concurrent(     // Modify formula here
           ClearCollect(
                        AssessmentByLocation,
                        SortByColumns(
                                      Filter(
                                             'Assessment By Locations',
                                             Location.Location = LookUp(
                                                                        Contacts,
                                                                         Contact = ContactID
                                                                  ).Location.Location
                                      ),
                                     "mzk_order"
                        )
           ),
           ClearCollect(
                         AssessmentByRole,
                         SortByColumns(
                                       Filter(
                                              'Assessment By Locations',
                                              Role.Role = LookUp(
                                                                 Contacts,
                                                                 Contact = ContactID
                                                          ).'Role (mzk_Role)'.Role
                                       ),
                                       "mzk_order"
                          )
           ),
           ClearCollect(
                          AssessmentByLocationAndRole,
                          SortByColumns(
                                        Filter(
                                               'Assessment By Locations',
                                               Location.Location = LookUp(
                                                                           Contacts,
                                                                           Contact = ContactID
                                                                    ).Location.Location,
                                               Role.Role = LookUp(
                                                                   Contacts,
                                                                   Contact = ContactID
                                                            ).'Role (mzk_Role)'.Role
                                         ),
                                         "mzk_order"
                           )
           )
);
If(
    (CountRows(AssessmentByLocation) >= CountRows(AssessmentByRole)) && (CountRows(AssessmentByLocation) >= CountRows(AssessmentByLocationAndRole)),
    ClearCollect(
        FinalAssessments,
        AssessmentByLocation
    );
    ForAll(
        RenameColumns(
            AssessmentByRole,
            "mzk_Assessment",
            "AssessmentbyRoleID"
        ),
        If(
            IsEmpty(
                Filter(
                    FinalAssessments,
                    Assessment.Assessment = AssessmentbyRoleID.Assessment
                )
            ),
            Collect(
                FinalAssessments,
                LookUp(
                    AssessmentByRole,
                    Assessment.Assessment = AssessmentbyRoleID.Assessment
                )
            );
            ForAll(
                RenameColumns(
                    AssessmentByLocationAndRole,
                    "mzk_Assessment",
                    "AssessmentbyLRID"
                ),
                If(
                    IsEmpty(
                        Filter(
                            FinalAssessments,
                            Assessment.Assessment = AssessmentbyLRID.Assessment
                        )
                    ),
                    Collect(
                        FinalAssessments,
                        LookUp(
                            AssessmentByLocationAndRole,
                            Assessment.Assessment = AssessmentbyLRID.Assessment
                        )
                    )
                )
            )
        )
    ),
    If(
        CountRows(AssessmentByRole) >= CountRows(AssessmentByLocationAndRole),
        ClearCollect(
            FinalAssessments,
            AssessmentByRole
        );
        ForAll(
            RenameColumns(
                AssessmentByLocation,
                "mzk_Assessment",
                "AssessmentbyLocationID"
            ),
            If(
                IsEmpty(
                    Filter(
                        FinalAssessments,
                        Assessment.Assessment = AssessmentbyLocationID.Assessment
                    )
                ),
                Collect(
                    FinalAssessments,
                    LookUp(
                        AssessmentByLocation,
                        Assessment.Assessment = AssessmentbyLocationID.Assessment
                    )
                );
                ForAll(
                    RenameColumns(
                        AssessmentByLocationAndRole,
                        "mzk_Assessment",
                        "AssessmentbyLRID"
                    ),
                    If(
                        IsEmpty(
                            Filter(
                                FinalAssessments,
                                Assessment.Assessment = AssessmentbyLRID.Assessment
                            )
                        ),
                        Collect(
                            FinalAssessments,
                            LookUp(
                                AssessmentByLocationAndRole,
                                Assessment.Assessment = AssessmentbyLRID.Assessment
                            )
                        )
                    )
                )
            )
        ),
        ClearCollect(
            FinalAssessments,
            AssessmentByLocationAndRole
        );
        ForAll(
            RenameColumns(
                AssessmentByLocation,
                "mzk_Assessment",
                "AssessmentbyLocationID"
            ),
            If(
                IsEmpty(
                    Filter(
                        FinalAssessments,
                        Assessment.Assessment = AssessmentbyLocationID.Assessment
                    )
                ),
                Collect(
                    FinalAssessments,
                    LookUp(
                        AssessmentByLocation,
                        Assessment.Assessment = AssessmentbyLocationID.Assessment
                    )
                );
                ForAll(
                    RenameColumns(
                        AssessmentByRole,
                        "mzk_Assessment",
                        "AssessmentbyRoleID"
                    ),
                    If(
                        IsEmpty(
                            Filter(
                                FinalAssessments,
                                Assessment.Assessment = AssessmentbyRoleID.Assessment
                            )
                        ),
                        Collect(
                            FinalAssessments,
                            LookUp(
                                AssessmentByRole,
                                Assessment.Assessment = AssessmentbyRoleID.Assessment
                            )
                        )
                    )
                )
            )
        )
    )
);
ClearCollect(
    assessment,
    SortByColumns(FinalAssessments,
        "mzk_order"
    )
);

Please make sure you have set the "Data row limit for non-delegable queries" option to maximum value -- 2000 within Advanced settings of App settings of your app.

 

Please consider set the OnStart property of App to above formula, then when your run your canvas app, then OnStart property would be executed. Also please turn off the "Use non-blocking OnStart rule" option within Advanced settings of your App settings of your app.

 

Please take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

We tried the approach that you mentioned but it does not work. The problem I see over here is creating a collection from a collection, using this it runs inside the studio but not after publishing it. 

 

Thanks

Syed Danish

Hi @syed_aalam001 ,

According to the issue that you mentioned, I could not reproduce your issue on my side. The formula that you provided is correct. Also please make sure your Network is in a good condition.

 

Please consider submit an assisted support ticket for further help through the following link:
https://powerapps.microsoft.com/en-us/support/pro

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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,597)