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

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Adding a large number of variables

(1) ShareShare
ReportReport
Posted on by 27

@trice602 I'm trying to use the add expression in ‘compose’ on a large number of variables -- I have 28 variables. I tried the below expression which isn't working. Any chance you know where I'm going wrong?

 

add(add(add(add(add(add(add(add(add(add(add(add(add(add(add(add(add(add(add(add(add(add(add(add(add(add(add(variables( 'Answer1' ),variables( 'Answer2' )),variables( 'Answer3' ),variables( 'Answer4' ),variables( 'Answer5' ),variables( 'Answer6' ),variables( 'Answer7' ),variables( 'Answer8' ),variables( 'Answer9' ),variables( 'Answer10' ),variables( 'Answer11' ),variables( 'Answer12' ),variables( 'Answer13' ),variables( 'Answer14' ),variables( 'Answer15' ),variables( 'Answer16' ),variables( 'Answer17' ),variables( 'Answer18' ),variables( 'Answer19' ),variables( 'Answer20' ),variables( 'Answer21' ),variables( 'Answer22' ),variables( 'Answer23' ),variables( 'Answer24' ),variables( 'Answer25' ),variables( 'Answer26' ),variables( 'Answer27' ),variables( 'Answer28' )))))))))))))))))))))))))))

I have the same question (0)
  • trice602 Profile Picture
    14,777 Super User 2025 Season 2 on at
    Re: Adding a large number of variables

    Hi @tcm213 ,

     

    There's a better way to add a large number of values and here's one way.

     

    In my example, assume my values are coming from a Form response.

     

    trice602_0-1694306122115.png

     

    So my form has 10 questions and to run a test my answers are 10, 20, 30, 40, 50, 60, 70, 80, 90, 100

     

    trice602_1-1694306181959.png

     

    Next I create a quick array of the values I want to add downstream, by putting the form responses in square brackets, separated by a comma shown below.

     

    trice602_2-1694306246588.png

     

    Next I create two integer values, both set to 0.

     

    trice602_3-1694306325323.png

     

    Next I add an apply to each (this will not automatically wrap your next action so you need to add it manually).  My output for the apply to each is my array total variable.

     

    I am using set variable temp 1 to the following expression:

     

    add(variables('sumtotal'),int(item()))

     

    Let's walkthrough what this totals.  Right now sumtotal = 0 and the first item in my array is 10 so I am setting the value of temp1 to 10.  Also note that my answers from the Form are strings so I convert them to integers during the add expression.

     

    In the next action, I am updating the value of sumtotal to temp1, so starting at 0, now is 10.

     

    Then this loops through all 28 values in your case and the ending results of sumtotal is the sum of all 28 values.

     

    trice602_4-1694306394623.png

     

     

    If this helps you keep going today, please mark as a solution so others can find this answer please!  It is a very common question.

     

    The results:  10 + 20+ 30 + 40+ 50 + 60 + 70 + 80+ 90 +100 = 550

     

    trice602_5-1694306750374.png

     

     

  • tcm213 Profile Picture
    27 on at
    Re: Adding a large number of variables

    @trice602 I'm trying to automate an email off of a form quiz based on an individual's quiz score. The first picture attached is the set up I have for each question in the flow and then the second picture shows that I want to send one email to those who score less than 23 and a different email to those who score 23 or more.

     

    1.JPG2.JPG

     

     

     

  • Verified answer
    trice602 Profile Picture
    14,777 Super User 2025 Season 2 on at
    Re: Adding a large number of variables

    Hi @tcm213 ,

     

    On the surface, the issue most likely is "quiz scoring" from Forms does not come into Power Automate so if your answers are not already numbers (like in my previous example when I thought you just wanted to add numbers), your form answers are coming over as the answer to the question, such as Option 1, not the question quiz value.  So consider this approach for quiz score totals for pass or fail conditions:

     

    trice602_0-1694318753750.png

    trice602_1-1694318796785.png

    trice602_2-1694318824845.png

     

     

    So the first thing I do here, is convert my answer to a quiz score value (for each question).  In this example, all my questions are choices, Option 1 and Option 2 are the answers.  If Option 1 is the correct answer, I setup an if statement in my compose for answer 1 as follows:

     

    This means the correct answer, Option 1 is worth 10 points, everything else is 0.  The highlighted green is the dynamic content from Get Responses answer 1.  The blue highlight is the correct answer, yellow are the score values.

     

    trice602_3-1694318984296.png

     

     

    I write a compose for every question, so in my example, I have 10 compose actions.

     

    Same as my other example, I set the array variable answers to the following, inside square brackets, comma separated.  I have 10 questions/answers in my example.

     

    trice602_4-1694319134018.png

     

    Initialize two new integer variables, set to 0

     

    trice602_5-1694319209645.png

     

     

    Inside an apply to each, I set the value of temp1 to an add expression:

     

    add(variables('sumtotal'),int(item()))
     
    trice602_6-1694319281725.png

     

    Then (above), I set the value of sumtotal to temp1.

     

    This will loop through all ten of my answers in my answer array and add of the values of the correct answers from the quiz.

     

    The first time it loops through it will add 0 + answer 1 score,

    The second time it loops through it will add the previous score (0 + answer 1 score) + answer 2 score,

    etc,etc,etc

     

     

    Next I have the score total condition.  If the sumtotal is 70 or greater, send pass email, else send fail email.

     

    trice602_7-1694319374760.png

     

     

  • Nived_Nambiar Profile Picture
    18,029 Super User 2025 Season 2 on at
    Re: Adding a large number of variables

    Hi @trice602 

     

    In addition, we can compute the sum of elements in array using this technique as well.

     

    Nived_Nambiar_0-1694321532807.png

     

    Expression used :  xpath(xml(outputs('Compose')),'sum(/root/Numbers)')

     

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

  • trice602 Profile Picture
    14,777 Super User 2025 Season 2 on at
    Re: Adding a large number of variables

    Nice! I will try this out now!!! 

  • tcm213 Profile Picture
    27 on at
    Re: Adding a large number of variables

    @trice602 thank you!! That bottom piece did the trick!

     

    Adding my flow in case it helps anyone else:

     

    I did the initialize variable + condition for all 28 questions in my quiz creating a set value of 1 for the correct answer and 0 for the incorrect answer. 

    1.JPG

    And then followed the bottom of Tom's flow, and that did the trick!

    2.JPG3.JPG4.JPG

  • trice602 Profile Picture
    14,777 Super User 2025 Season 2 on at
    Re: Adding a large number of variables

    Nice! @tcm213 great to hear!  Always glad to help! Tom

     

     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 614 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 401 Moderator

#3
chiaraalina Profile Picture

chiaraalina 282

Last 30 days Overall leaderboard