9 Replies Latest reply on Dec 3, 2013 6:05 AM by kb-NetCom

# Math Function to sum only positive or negative Numbers

Good morning,

I need to know, if I can select from several rows all the items which are positiv or all items which are negativ ...

For a better understanding: in the formular are 20 rows which calculate if things are delivered or not. If not delivered and on the bill  -  it would be a value which has to be subtracted. The other way around, if there are goods which are delevered, but not on the bill, we have to add the price for it - positive numbers !

I hope there is a function for this - otherwise it is a very uncomfortable if .. function.

Klaus

• ###### 1. Re: Math Function to sum only positive or negative Numbers

You need to iterate over all the fields, checking if they're positive or negative, and then adding them up. It's not complicated.

• ###### 2. Re: Math Function to sum only positive or negative Numbers

sorry - I didn´t realize it.

Thanks a lot !!!!!

Kind regards,

Klaus

• ###### 3. Re: Math Function to sum only positive or negative Numbers

sorry, but I thought: - Yes, this sounds good and logical!

But I think, I am making mistakes.

if ("Gesamt_Preis_01"<0;"Gesamt_Preis_02"<0;"Gesamt_Preis_03"<0;"Gesamt_Preis_04"<0); event.value = "";

or ??

sumif (Number("Gesamt_Preis_01")<0);Number("Gesamt_Preis_02")<0);Number("Gesamt_Preis_03")<0);N umber("Gesamt_Preis_04")<0)); event.value = "";

I hope my intension is not far away from the truth :-).

Thank you ....

Klaus

• ###### 4. Re: Math Function to sum only positive or negative Numbers

You are trying to do in one expression something that needs lots of statements. Use an if statement to test each element in turn ("iterate over them").

• ###### 5. Re: Math Function to sum only positive or negative Numbers

Sorry ... I am not sure to understand, what you mean with "iterate over them" ....

Isn´t it correct, in "calculation" to mark all fields which have to be checked, then to check every Field in "validation" with:

if (a<0; b<0; c<0) ; event.value="";

or is it more like:

if (number(a<0); number(b<0); Number(c<0)) ; event.value="";

I am sorry, but I have tried this - without success :-(.

Thanks for a short help !!

:-)

• ###### 6. Re: Math Function to sum only positive or negative Numbers

No, neither one is anything like JavaScript. You cannot make lists of things to process in this way. They must be done one at a time and written that way.

First set a total to zero.

Write one separate line for each field, adding to the total only if the value is applicable.

To "iterate over" something is to do the same thing for each separate element in it, but to do the thing separately.

• ###### 7. Re: Math Function to sum only positive or negative Numbers

Hmmm .. :-),

probably I understand a bit more. Just to "set a total to zero"

e.g.

every field has to be checked out ...

if(number(a<0); event.value="";

if(number(b<0); event.value="";

if(number(c<0); event.value="";

Do you mean it in this way .. ??

I gonna try this :-).

Thanks

• ###### 8. Re: Math Function to sum only positive or negative Numbers

No, not really. Understand that setting event.value is what you do with the final result; you do it once only at the end.

Have a variable, we'll call it total.

You set a variable to zero in the usual way, probably with a var statement.

Then you have a series of if statements, each one adding to total if and only if you need to. I have no idea what number() means or what number(a<0) is supposed to mean, nor how you get the values. This doesn't look anything like JavaScript to me, I think you may be trying to borrow too much from another language you understand better. You need to learn JavaScript if you are to write it!

• ###### 9. Re: Math Function to sum only positive or negative Numbers

... ok. I think you are right. It seems to be a mixture of my better known Visual Basic and Excel functions ...

Well, I will try now to find out how I have to write it.

Thanks a lot for your patience.

I will tell you the result - maybe tomorrow.