cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
jesenavaranjan
Level: Powered On

Advice on For ALL Function

Hi, I am using a ForALL function, 

to patch items from a gallery (list of questions, and 77 anwers)

the patch take a while - is there any way to speed up this patch?

As it's looping through and doing 77 updates/new statements to the DB

4 REPLIES 4
eka24
Level 10

Re: Advice on For ALL Function

Please what is your datasource and can you copy and paste the Code.
Super User
Super User

Re: Advice on For ALL Function

Hi @jesenavaranjan 

If it's a SQL Server DB, using a Stored Procedure and Flow will improve performance.

jesenavaranjan
Level: Powered On

Re: Advice on For ALL Function

It is  SQL Back End

- The formula is quite long and contains many parts.

But the main logic

- Collects a gallery into a collection

- Adds various fields through lookups

- Patches each row into a DB one by one

 

Jese

GarethPrisk
Level: Powered On

Re: Advice on For ALL Function

Jese,

When you say slow - how long is it taking?

There are probably ways to speed up the processing:

  • Add a RowId (number) column to your collection
  • Use a Concurrent function and split the collection up
  • Filter each branch (let's say 5) to divide the total # in the collection equally (using rounding logic) for each Concurrent branch
  • Then Patch in each Concurrent branch by filtering out the collection to that subset of records

Additionally, if the problem is more around "the app is slow because I don't see progress" - which is common for users.

  • Display a progress bar, maybe two overlapping shape controls (shpTotal, shpProgress)
    • Adjust the width of the progress control, based on how far the process as come along
    • See example below
  • Add a blocking mechanism of some sort, so the User cannot do other actions but is also shown that thing are progressing
ClearCollect(
    colProgress,
    {
        counterType: "Progress",
        counterCount: 0
    },
    {
        counterType: "Total",
        counterCount: CountRows(colAccounts)
    }
);
ForAll(
    colAccounts,
    UpdateIf(
        colProgress,
        counterType = "Progress",
        {counterCount: counterCount + 1}
    );
    Patch(
        Accounts,
        Defaults(Accounts),
        {name: staticAccountName}
    )
)

The example above uses CDS Account entity, and a collection based on some static data I had. The concept still applies, for deriving a total, and increment the progress on each loop of the ForAll.

Then you can see a control, such as the Width of the shpProgress shape to

shpTotal.Width * (LookUp(
    colProgress,
    counterType = "Progress",
    counterCount
) / LookUp(
    colProgress,
    counterType = "Total",
    counterCount
))

 

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,443)