Add a column in with total value calculation field
Hi,
I a calculation field i have the following javascript :
var name = @All of Name X with nulls;
var amount = @All of Amount X with nulls;
var lines = [];
for(var i = 0; i < name.length; i = i+1)
{lines.push(name[i] + " | " + amount[i])}
"Name | Amount | Total amount \n" +
" --- | --- | --- \n" +
lines.join("\n")
Which gives me the following result :
I'd like to have the following result in the column "Total amount" :
500
710
760
772
Which is the sum of numbers of all previous amount.
Does anybody knows how to do this?
-
Hi Nicolas;
your above code isn't correct for the case "with nulls" (works only correct if there is no null). Here's the correct code plus the enhancement for the 3. column.
var name = @All of Name X with nulls;
var amount = @All of Amount X with nulls;
var lines = [];
var total = 0;
for(var i = 0; i < name.length; i++){
var am = Number(amount[i][0]) || 0;
total += am;
lines.push(name[i][0] + " | " + am + " | " + total);
};
"Name | Amount | Total amount \n" +
" --- | --- | --- \n" +
lines.join("\n")Rainer
Please sign in to leave a comment.
Comments
1 comment