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 / Iterate around Acollec...
Power Apps
Answered

Iterate around Acollection

(0) ShareShare
ReportReport
Posted on by 1,302

Hi

 

I have a financial collection which I want to iterate around :-  Financial Year, CAPEX, OPEX

 

This collection has four entries :- 
FY18/19, CAPEX = 1, OPEX=2

FY19/20, CAPEX = 10, OPEX=20

FY20/21, CAPEX = 100, OPEX=200

FY21/22, CAPEX = 1000, OPEX=2000

 

So I want to iterate around the collection and do some calculations on the OPEX and CAPEX amounts.

like add the CAPEX and OPEX to a value in a variable.

 

I cannot use ForAll(FYCollection, UpdateContext({vTotalCAPEX:vTotalCAPEX + CAPEX}); UpdateContext({vTotalOPEX:vTotalOPEX + OPEX});

); nor the Set() equivalent.

 

How can I achieve my Objective ?

 

Thanks

 

Nigel

Categories:
I have the same question (0)
  • xzDan Profile Picture
    350 on at

    Can you not use an AddColumn(<source>,"Sum Column",CAPEX+OPEX)?

     

    Or Set(myVariable, Sum(<Source>,CAPEX)+Sum(<Source>,OPEX))

  • NPrice99 Profile Picture
    1,302 on at

    HI @xzDan 

     

    You certainly cannot use Set inside a ForAll.

     

    I will have a look at your other option.

     

    Thanks

     

    Nigel

  • xzDan Profile Picture
    350 on at

    You are right you cannot. Both my proposal would not use ForAll at all

  • v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @NigelP ,

    Do you want to calculate the sum of CAPEX column/OPEX column of all records in your FYCollection, and save them into a separated variable?

    Based on the formula that you mentioned, I think there is something wrong with it. Currently, setting a variable (context variable or global variable) within a ForAll function is not supported within PowerApps currently.

     

    Based on the needs that you mentioned, I think the Sum function could achieve your needs. I have made a test on my side, please take a try with the following workaround:

    Set the OnSelect property of the "Calculate" button to following:

    Set(vTotalCAPEX, Sum(FYCollection, CAPEX));
    Set(vTotalOPEX, Sum(FYCollection, OPEX))

    More details about the Sum function, please check the following article:

    Sum function

     

    Best regards,

  • NPrice99 Profile Picture
    1,302 on at

    Hi @v-xida-msft 

     

    Thanks for this.

    So now I have two collections each one having a common column - FY.

     

    I now want to compare the collections based upon the common column FY.

    So for each value in the common column (FY), I want to compare the values in the other columns.

    So if Collection1 has FY, ProjectCAPEX,ProjectOPEX,ProjectID

    and Collection2 has FY, BudgetCAPEX, BudgetOPEX,ProjectID

     

    I want to know what Projects (ie ProjectID) where ProjectCAPEX > BudgetCAPEX or ProjectOPEX > BudgetOPEX

    for each FY.

     

    Thanks

     

    Nigel

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

    Hi @NigelP ,

    Do the Collection1 and Collection2 have common columns -- FY and ProjectID?

    Further, do you want to compare the the values in the other columns based on the common column FY?

     

    I have made a test on my side, please take a try with the following workarund (set the OnSelect property of the Button to following😞

    Clear(FinalProjectIDCollection);
    ForAll( Collection1, If(
    Collection1[@ProjectCAPEX] > LookUp(Collection2, FY = Collection1[@FY], BudgetCAPEX) || Collection1[@ProjectOPEX] > LookUp(Collection2, FY = Collection1[@FY], BudgetOPEX),
    Collect(FinalProjectIDCollection, Collection1[@ProjectID])
    ) )

    When you execute above formula, the Projects (ProhectID) which meets your needs would be populated within the FinalProjectIDCollection collection.

     

    More details about ForAll function, please check the following article:

    ForAll function

     

    Please take a try with above solution, then check if the issue is solved.

     

    Best regards,

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!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 993

#2
Valantis Profile Picture

Valantis 675

#3
11manish Profile Picture

11manish 545

Last 30 days Overall leaderboard