Community discussions

MikroTik App
 
galaxyaord
newbie
Topic Author
Posts: 25
Joined: Fri Nov 01, 2019 11:11 pm

Sum values obtained with foreach

Sat Feb 13, 2021 9:49 am

Greetings. I want to obtain the limit-at variable of all the queues that correspond to a parent and add all its values in the same variable, how can I do this? I run the following commands:
 :foreach b in=[/queue simple find parent=example-parent] d={
	:global test [/queue simple get $b limit-at]; :put $test
	} 
but instead of giving me the total value they are printed individually line by line, for example:

1M / 5M
1M / 2M
2M / 1M

How can I do so that when consulting the variable for example $ result it gives me the total sum? In this case: put $result = 3M/8M
 
Emil66
Frequent Visitor
Frequent Visitor
Posts: 62
Joined: Tue Aug 28, 2018 2:09 am

Re: Sum values obtained with foreach

Sat Feb 13, 2021 11:44 am

Sums are obtained by adding stuff up. Computers only do what they're told. Try telling the computer to add something.
 
galaxyaord
newbie
Topic Author
Posts: 25
Joined: Fri Nov 01, 2019 11:11 pm

Re: Sum values obtained with foreach

Sat Feb 13, 2021 2:58 pm

Sums are obtained by adding stuff up. Computers only do what they're told. Try telling the computer to add something.
I publish precisely because I cannot find how to combine all the results in a single variable
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Sum values obtained with foreach

Sat Feb 13, 2021 8:05 pm

Split the data inn to two variables (do not need to use global her so use local variable)
Then sum up
https://wiki.mikrotik.com/wiki/Manual:S ... _Operators

Who is online

Users browsing this forum: caldo85 and 21 guests