web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Update Context during ...
Power Apps
Unanswered

Update Context during ClearCollect with Filter

(0) ShareShare
ReportReport
Posted on by 41

Hi,

I'm trying to updatecontext for a progress bar when creating a collection. After/before filter, that takes place I am trying to increment the locloadingpercentage by 0.05. When I add the updatecontext to the formula, it doesn't create the full collection, any suggestions?

Set (varLoading, true); 
UpdateContext({
 locLoadingMessage: "Preparing",
 locLoadingPercent: 0.05
});
Refresh(RegisteredKits);
Refresh(Wards);
UpdateContext({
 locLoadingMessage: "Loading Wards",
 locLoadingPercent: 0.07
});
Refresh(Documents);
UpdateContext({
 locLoadingMessage: "Loading Documents",
 locLoadingPercent: 0.10
});
Refresh(NonNSFTStaff);
UpdateContext({
 locLoadingMessage: "Loading Staff",
 locLoadingPercent: 0.15
});
Refresh(DistributedKits);
UpdateContext({
 locLoadingMessage: "Loading Distributed Kits",
 locLoadingPercent: 0.17
});
UpdateContext({
 locLoadingMessage: "Loading Registered Kits",
 locLoadingPercent: 0.2
});
 UpdateContext({
 locLoadingMessage: "Please Wait",
 locLoadingPercent: 0.3
});
ClearCollect (
 colKitData,
 Filter (
 RegisteredKits,
 IsBlank(BoxNumber)
 ),
 Filter (
 RegisteredKits,
 BoxNumber > 0 && BoxNumber < 500
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 500 && BoxNumber < 1000
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 1000 && BoxNumber < 1500
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 1500 && BoxNumber < 2000
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 2000 && BoxNumber < 2500
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 2500 && BoxNumber < 3000
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 3000 && BoxNumber < 3500
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 3500 && BoxNumber < 4000
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 4000 && BoxNumber < 4500
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 4500 && BoxNumber < 5000
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 5000 && BoxNumber < 5500
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 5500 && BoxNumber < 6000
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 6000 && BoxNumber < 6500
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 6500 && BoxNumber < 7000
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 7000 && BoxNumber < 7500
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 7500 && BoxNumber < 8000
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 8000 && BoxNumber < 8500
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 8500 && BoxNumber < 9000
 ),
 Filter (
 RegisteredKits,
 BoxNumber >= 9500 && BoxNumber < 10000
 )
);
UpdateContext({
 locLoadingMessage: "Kits Loaded",
 locLoadingPercent: 0.8
});
// Collects and groups the records by ward/team
ClearCollect(
 colKitsGrouped,
 SortByColumns(
 GroupBy(
 AddColumns(
 colKitData,
 "WardTeam",
 WardorTeam
 ),
 "WardTeam",
 "WardTeamGroup"
 ),
 "WardTeam",
 Ascending
 )
);
UpdateContext({
 locLoadingMessage: "Preparing Data",
 locLoadingPercent: 0.9
});
// Adds a row number to be used later when filtering the galleries
Clear(colKitsGroupedRowNo);
ForAll (
 colKitsGrouped,
 Collect(
 colKitsGroupedRowNo,
 Last(
 FirstN(
 AddColumns(
 colKitsGrouped,
 "RowNumber",
 CountRows(colKitsGroupedRowNo) + 1
 ),
 CountRows(colKitsGroupedRowNo) + 1
 )
 )
 )
);
UpdateContext({
 locLoadingMessage: "Complete",
 locLoadingPercent: 1.0
});
Set (
 varLoading,
 false
);

 

Thanks
 

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    154,399 Most Valuable Professional on at

    Hi @ChrisBrownNSFT ,

    It does not make logical sense as your Variable updates are totally separate to your Collection Activities.

    However I have another way of collecting all the data if you have a sequential identifier as you do - refer to my blog on the With() Statement

    ClearCollect (
     colKitData,
     Filter (
     RegisteredKits,
     BoxNumber=Blank()
     )
    );
    With(
     {
     wSets: 
     With(
     {
     wLimits: 
     With(
     {
     wLimit: 
     Sort(
     Filter(
     RegisteredKits,
     BoxNumber>0
     ),
     BoxNumber,
     Descending
     )
     },
     RoundDown(
     First(wLimit).BoxNumber / 500,
     0
     ) + 1
     )
     },
     AddColumns(
     RenameColumns(
     Sequence(
     wLimits,
     0,
     500
     ),
     "Value",
     "LowID"
     ),
     "HighID",
     LowID + 500
     )
     )
     },
     ForAll(
     wSets As MaxMin,
     Collect(
     colKitData,
     Filter(
     RegisteredKits,
     BoxNumber > MaxMin.LowID && BoxNumber <= MaxMin.HighID
     )
     )
     )
    )
    

    Try this and see if it makes a difference.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • ChrisBrownNSFT Profile Picture
    41 on at

    Hi Warren,


    I'm erroring on BoxNumber=Blank...

  • WarrenBelz Profile Picture
    154,399 Most Valuable Professional on at

    Free-typed - now fixed (I thought you might have picked that one up)

    @ChrisBrownNSFT ,

  • ChrisBrownNSFT Profile Picture
    41 on at

    I have now updated it, and it's not collecting all the data, infact only collecting those without a box number...

     

    Set (varLoading, true); 
    UpdateContext({
     locLoadingMessage: "Preparing",
     locLoadingPercent: 0.00
    });
    UpdateContext({
     locLoadingMessage: "Preparing",
     locLoadingPercent: 0.05
    });
    Refresh(DistributedKits);
    UpdateContext({
     locLoadingMessage: "Loading Distributed Kits",
     locLoadingPercent: 0.17
    });
    UpdateContext({
     locLoadingMessage: "Loading Registered Kits",
     locLoadingPercent: 0.2
    });
     UpdateContext({
     locLoadingMessage: "Please Wait",
     locLoadingPercent: 0.3
    });
    ClearCollect (
     colKitData,
     Filter (
     RegisteredKits,
     BoxNumber=Blank()
     )
    );
    With(
     {
     wSets: 
     With(
     {
     wLimits: 
     With(
     {
     wLimit: 
     Sort(
     Filter(
     RegisteredKits,
     BoxNumber>0
     ),
     BoxNumber,
     Descending
     )
     },
     RoundDown(
     First(wLimit).BoxNumber / 500,
     0
     ) + 1
     )
     },
     AddColumns(
     RenameColumns(
     Sequence(
     wLimits,
     0,
     500
     ),
     "Value",
     "LowID"
     ),
     "HighID",
     LowID + 500
     )
     )
     },
     ForAll(
     wSets As MaxMin,
     Collect(
     colKitData,
     Filter(
     RegisteredKits,
     BoxNumber > MaxMin.LowID && BoxNumber <= MaxMin.HighID
     )
     )
     )
    );
    UpdateContext({
     locLoadingMessage: "Kits Loaded",
     locLoadingPercent: 0.7
    });
    // Collects and groups the records by ward/team
    ClearCollect(
     colKitsGrouped,
     SortByColumns(
     GroupBy(
     AddColumns(
     colKitData,
     "WardTeam",
     WardorTeam
     ),
     "WardTeam",
     "WardTeamGroup"
     ),
     "WardTeam",
     Ascending
     )
    );
    UpdateContext({
     locLoadingMessage: "Preparing Data",
     locLoadingPercent: 0.8
    });
    // Adds a row number to be used later when filtering the galleries
    Clear(colKitsGroupedRowNo);
    ForAll (
     colKitsGrouped,
     Collect(
     colKitsGroupedRowNo,
     Last(
     FirstN(
     AddColumns(
     colKitsGrouped,
     "RowNumber",
     CountRows(colKitsGroupedRowNo) + 1
     ),
     CountRows(colKitsGroupedRowNo) + 1
     )
     )
     )
    );
    Refresh(RegisteredKits);
    Refresh(Wards);
    UpdateContext({
     locLoadingMessage: "Loading Wards",
     locLoadingPercent: 0.85
    });
    Refresh(Documents);
    UpdateContext({
     locLoadingMessage: "Loading Documents",
     locLoadingPercent: 0.9
    });
    Refresh(NonNSFTStaff);
    UpdateContext({
     locLoadingMessage: "Loading Staff",
     locLoadingPercent: 0.95
    });
    UpdateContext({
     locLoadingMessage: "Complete",
     locLoadingPercent: 1.0
    });
    Set (
     varLoading,
     false
    );

    I've then tried it with <>Blank(), that then collects 2000 records, but there are 3573 in my normal collection, and =!Blank() and that doesn't collect anything.

     

  • WarrenBelz Profile Picture
    154,399 Most Valuable Professional on at

    @ChrisBrownNSFT ,

    Sorry but the syntax works (I just re-tested and collected 16,200 records with it) - I am not able to debug something as complex as this on unfamiliar data.

    You might try it without the Variables - that will be a good test of what is happening.

    As I mentioned, it is not logical that a Variable setting should affect a Collection which is a separate process.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 94

#2
WarrenBelz Profile Picture

WarrenBelz 82 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 38 Super User 2026 Season 1

Last 30 days Overall leaderboard