question

Jason P2 avatar image
0 Likes"
Jason P2 asked Joerg Vogel answered

sum value in array

I have a token for each warehouse order. I need to get the total quantity per order, so I need to sum up the array token.Qty. How do I create a label that sums the array for example token.OrderQty = 11

FlexSim 19.2.3
array
capture87.png (15.8 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Regan Blackett avatar image
2 Likes"
Regan Blackett answered

You could copy this and paste it into the Code Editor for the Value field on an Assign Labels activity:

Array theArray = token.Qty;
double aggregate;

for(int i = 1; i <= theArray.length; i++)
    aggregate += theArray[i];
    
return aggregate;
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered

By a table query over the array length with a SUM clause

Array qty = [12,1.23,3.56];
double sum = Table.query("SELECT SUM($2) FROM $1",
      			    /*$1*/ qty.length,
      			    /*$2*/ qty[$iter(1)]
  			)[1][1];
print(sum);
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.