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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Increment and Decremen...
Power Apps
Answered

Increment and Decrement of Values inside For All

(0) ShareShare
ReportReport
Posted on by 35
Hello All,
I have variable called currentQuarter have value =1 (can be anything between 1 to 4) now I need to add this inside the collection with number rows equal tp varQuarterCount i.e. 2 or can be more than 2.
I am using for all here , it is creating the collection having 2 rows but at the same time I want varCurrentQuarter value to be changed so I am also using If inside for all to increase/decrease value of varCurrentQuarter variable.
But Collection having two rows with same value of varCurrentQuarter = 1 instead it should be two in second row 
Below is the formula which I am using:

If(Count Rows(collQuarterlyDetails)<varQuarterCount,
ForAll( Sequence( varQuarterCount ),
Collect(collQuarterlyDetails,{PlannedCost:0,BudgetedCost:0,ActualCost:0,Quarter:Concatenate("Q",Text(varCurrentQuarter))});

If(varCurrentQuarter = 4,
varCurrentQuarter-3,
varCurrentQuarter+1
)));

 
Deepshikha21_0-1622486747517.png

In second row of collection it should have Q2 instead of Q1 as Value is increasing inside for all for varCurrentQuarter variable.

If any one can help me to increase/decrease value of varCurrentQuarter variable inside for all based on if condition.

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Deepshikha21 
    ForAll is not a For/Loop like in a development platform (which PowerApps is not).  It is a function that returns a Table of records shaped in any way that you want.

    Also to know, Sequence is a function that returns a Table of records with a Value column.  The number of rows and the Value in each record is dependent on the value you provide for the Sequence (among other things).

     

    Please consider changing your Formula to the following:

    If(CountRows(collQuarterlyDetails)<varQuarterCount,
     Collect(collQuarterlyDetails,
     ForAll( Sequence(varQuarterCount),
     {PlannedCost:0, BudgetedCost:0, ActualCost:0, Quarter:"Q" & Text(Value)}
     )
     )
    ) 
    

    ForAll Will create a table of sequential values based on varQuarterCount and will have one record for each iteration of the sequence table.  The Value of sequence is used to populate the Quarter column of your record.

    Final results of ForAll - a table that is put in a collection in this case.

     

    I hope this is helpful for you. 

  • CNT Profile Picture
    10,921 Super User 2024 Season 1 on at

    @Deepshikha21 The values are not changing b'coz varCurrentQuarter-3 & varCurrentQuarter+1 are not really changing the value of varCurrentQuarter. Also you can't use Set() inside a ForAll(). So you'll have to use a collection for varCurrentQuarter, Try this,

     

     

    If(CountRows(collQuarterlyDetails)<varQuarterCount,
     ClearCollect(colQuarterCount, varQuarterCount);
     ForAll(Sequence(varQuarterCount),
     Collect(collQuarterlyDetails, 
     {PlannedCost:0,BudgetedCost:0,ActualCost:0,Quarter:Concatenate("Q",Text(First(varQuarterCount).Value))});
     If(First(varQuarterCount).Value= 4,
     ClearCollect(colQuarterCount, First(varQuarterCount).Value-3),
     ClearCollect(colQuarterCount, First(varQuarterCount).Value+1)
     )
     )
    );

     

     

  • Verified answer
    Deepshikha21 Profile Picture
    35 on at

    Hi @CNT , Thanks for your help I tried implementing your formula but it was showing me error of "The Function can't be invoked inside For All" while trying to update collection values.

    Error.png

    So I have updated the formula to use Update If to update values inside for All, and now it is working fine.

    If(CountRows(collQuarterlyDetails)<varQuarterCount,
           ClearCollect(collQuarterCount1, varCurrentQuarter);
           ForAll(Sequence(varQuarterCount),
                 Collect(collQuarterlyDetails,                           {PlannedCost:0,BudgetedCost:0,ActualCost:0,Quarter:Concatenate("Q",Text(First(collQuarterCount1).Value))});
                If(
                     First(collQuarterCount1).Value= 4,
                      UpdateIf( collQuarterCount1, Value = 4, { Value: Value -3 } ),
                     UpdateIf( collQuarterCount1, Value < 3, { Value: Value +1 } )
                   )
           )
    );
    Value of Quarter is updating by using Update if.

    Deepshikha21_0-1622530849516.png

     

     

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Deepshikha21 

    Just as a word of help to you perhaps - you are really trying to make PowerApps work like a development platform when you look at a ForAll like that.  If you look at it as a function for creating a Table and understand that PowerApps is designed around the concepts of Excel - you will make your PowerApp designs much easier to make and troubleshoot.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard