I created a collection using ClearCollect that collects data from my sharepoint list. Then I have a label that shows the sum of one of the columns in the collection. I put the collection in the app OnStart property so that when the app loads, the collection is populated and the label displays the column sum. At least this is how I understood that it should work, but it didn't work. It only works when I manually run App OnStart.
Then I tried to put the collection in the OnVisible property of one of my screens and the issue is the same. It only works when I manually go to another screen and come back to the screen that has the collection. I now have no idea what could be causing this and what I can do about it.
This is what I have in my app OnStart/OnVisible property of the screen...
ClearCollect(colBudgetFilter,
If(User().Email=lbl_UnitControls_DeptHead.Text,
Filter(Budgets, Department.Value = lbl_UnitControls_Dept.Text),
Filter(Budgets, Unit.Value = lbl_UnitControls_Unit.Text)));
This is what I have in the Text property of the label...
Sum(colBudgetFilter, StartingBudget)
By the way, I did all this to avoid the delegation warning that comes with using the SUM function with a sharepoint datasource...
I would really appreciate any help. Thanks.
P.S: My sharepoint list has only 2 rows.
This is how Power Apps canvas application works in "edit" mode of application (from Power Apps maker portal).
Once you publish the application and run it, it will show the sum of SharePoint list column values properly when the app loads (App.OnStart
executes automatically on app load).
If you are adding/updating SharePoint list items from same/another app and if you want to get the current sum, you will have to collect the collection again after new item is added or existing item is updated.
Example 1: You are adding new item in same SharePoint list from same application on button click.
Then OnSelect
property of the button should be something like this:
// Add new item using Patch function
Patch(...);
// Populate collection again
ClearCollect(
colBudgetFilter,
If(
User().Email=lbl_UnitControls_DeptHead.Text,
Filter(Budgets, Department.Value = lbl_UnitControls_Dept.Text),
Filter(Budgets, Unit.Value = lbl_UnitControls_Unit.Text)
)
);
Example 1: You want to load the latest sum from SharePoint list on button click (say "Refresh" button).
Then OnSelect
property of the button should be something like this:
// Refresh SharePoint data source
Refresh(Budgets);
// Populate collection again
ClearCollect(
colBudgetFilter,
If(
User().Email=lbl_UnitControls_DeptHead.Text,
Filter(Budgets, Department.Value = lbl_UnitControls_Dept.Text),
Filter(Budgets, Unit.Value = lbl_UnitControls_Unit.Text)
)
);