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 / Getting the total numb...
Power Apps
Answered

Getting the total number each item in the collection.

(0) ShareShare
ReportReport
Posted on by 846 Moderator

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
 )
 )
)

 



Categories:
I have the same question (0)
  • v-bofeng-msft Profile Picture
    Microsoft Employee on at

    Hi @kej ,

     

    Please try:

    Filter(
    ForAll(
     Sequence(CountRows(colWeightOrder),1,1),
     {
     Name:Index(Sort(colWeightOrder,Name),Value).Name,
     Weight:Index(Sort(colWeightOrder,Name),Value).Name,
     totalWeight:Sum(FirstN(Sort(colWeightOrder,Name),Value),Weight)
     }
    ),totalWeight<170)

     

    Best Regards,
    Bof

  • KevinGador Profile Picture
    846 Moderator on at

    it worked! I need to study these functions it all looks complicated.... however I forgot to mention that the collection needs to be in descending order meaning the first thing that it will try to add to that total weight should be the highest number.
    currently the results are outputting this however it should be starting to sum starting 80, so should only see xyz80 and xyz71


    kej_0-1710384897747.png

     

  • Verified answer
    v-bofeng-msft Profile Picture
    Microsoft Employee on at

    Hi @kej ,

     

    Please try:

    Filter(
    ForAll(
     Sequence(CountRows(colWeightOrder),1,1),
     {Name:Index(Sort(colWeightOrder,Weight,SortOrder.Descending),Value).Name,Weight:Index(Sort(colWeightOrder,Weight,SortOrder.Descending),Value).Weight,totalWeight:Sum(FirstN(Sort(colWeightOrder,Weight,SortOrder.Descending),Value),Weight)}
    ),totalWeight<170);

     

    Best Regards,

    Bof

  • KevinGador Profile Picture
    846 Moderator on at

    thank you so much! Ill have to study these functions now.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 325 Most Valuable Professional

#2
11manish Profile Picture

11manish 165

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 88 Super User 2026 Season 1

Last 30 days Overall leaderboard