Sum of value inside a repeat and outside

Hi,

after long time I have to do sum values from a repeat but I don’t remember how to set up the variables.

The Server Connect is contains a query “Sellers” that list all the sellers. I set up a repeat where for each seller list the transactions and a variable that “count” the transaction.

I would make full sum of all transaction…

(I know that to get the total number of transactions, it would be enough to do a simple query. but at this point I would like to do it with variables to understand how it works to pass values from inside the repeat to outside the repeat.)

Here the server connect:

Schermata 2022-01-12 alle 12.13.07

the value count_transaction give the right value per each repeat… but how I can take this value out of repeat?

Thank you

Pseudo-code:

count_transaction = 0
total_transaction = 0
loop:
    count_transaction = query_transactions.count()
    total_transaction = total_transaction + count_transaction

console.log(total_transaction)

You need to move total_transaction to inside the loop, so the sum is actually performed at each repeat.

An exercise you can do, is to grab a paper and run the code by hand:

count_transaction = 0
total_transaction = 0
loop:
    # Round 1
    count_transaction = 10 (example)
    total_transaction = 0 + 10 #  10
    
    # Round 2
    count_transaction = 20 (example)
    total_transaction = 10 + 20 # 30

console.log(total_transaction) # 30

Edit: I haven’t tested this on Wappler, this is what I would do on a regular programming language. If you experience any issues feel free to let me know!

thank you but I already made such kind of configuration. I don t understand how to do in Wappler.

I cannot understand how to take a value out of the repeat

if you try to choose a value in a picker then it should show the values under the repeat.

No it doesn’t :frowning:

Maybe need full reinstall of Wappler ?

on the repeat itself in server connect, are you adding all of the output fields that you need to the repeat from your query?

and do you have the output box checked on the repeat?

you can also look in developer tools in the browser to see what the action script is returning in the browser

Hi! I take the value out of the repeat with the global name in set value. Not behind pc now so don’t remember the details

Use the Global Name, when using Name it will set a variable in the current scope, so the variable is only within the repeat, setting the Global Name will set a global variable.

1 Like

thank you @patrick

It is correct when I pick up the variable with Global Name outside the repeat it write like that ?

Schermata 2022-01-13 alle 11.59.22

The total_items within the repeat will assign to the local scope of the repeater if you use Name, by using Global Name it will assign the value to the global scope and not the inner scope of the repeater, updating the outer variable.

The value expression can stay the same, just move the name to global name.