I am practicing some stuff in power apps.
I have this sample collection
ClearCollect(
colWeightOrder,
Sort(
[
{
Name: "XYZ20",
Weight: 20,
TotalWeight: 0,
Index: 0
},
{
Name: "XYZ80",
Weight: 80,
TotalWeight: 0,
Index: 1
},
{
Name: "XYZ55",
Weight: 55,
TotalWeight: 0,
Index: 2
},
{
Name: "XYZ71",
Weight: 71,
TotalWeight: 0,
Index: 3
},
],Weight,SortOrder.Descending
)
)
what I want to do is whenever a checkbox is checked it will get the items in the collection and store this in another collection. More of like a for loop where it adds its weight per item for example
totalWeight = totalWeight + weight[x]
and when it reaches a threshold, it will stop adding that item to the collection for example
totalWeight < 170
and then display it in a dropdown. I have the items property of my dropdown like this
If( Checkbox1.Value,
//display the collection of items that reached a certain amount of weight,
//display all the items in the collection
)
Initially I thought of creating a collection in the oncheck propery of the checkbox.
Then adding another column named totalWeight but I have no idea how to do this. Any guidance or solution would be great
EDIT:
I've thought about this formula, however its still showing every item. the condition varTotalWeight < 170 is always evaluating to true.
ClearCollect(
colCustomWeightOrder,
ForAll(
colWeightOrder,
If(
varTotalWeight < 170,
varTotalWeight = varTotalWeight + ThisRecord.Weight;ThisRecord.Name,
false
)
)
)