cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Super User
Super User

Re: Creating Collection which is a union of different collections

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

Highlighted
Community Support
Community Support

Re: Creating Collection which is a union of different collections

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.
Highlighted
Frequent Visitor

Re: Creating Collection which is a union of different collections

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

Highlighted
Community Support
Community Support

Re: Creating Collection which is a union of different collections

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

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

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