3 Replies Latest reply: Oct 23, 2012 4:49 AM by annie.lovelace

# Calculate the sum of an expression

Hello,

I have a question concerning a sum.

I have two columns :

The first column is the state (input/output)

The second is a value.

I want to make the sum of these values : when the value is an input I add the value to the sum and when the value is an output, I remove this value to the sum.

I know that it is an expression in my graph, but I don't know how to do that......

Annie

• ###### Re: Calculate the sum of an expression

Hi Annie,

I would suggest creating a flag in your script for the state that is either 1 or -1:

If(State='input',1,-1) as StateFlag

Then you can use this in your calculation:

Value * StateFlag

• ###### Re: Calculate the sum of an expression

Thank youn Jphannes, you made my day =)

• ###### Re: Calculate the sum of an expression

Hi Annie,

let's assume you have a chart with an expression to sum up a field called Val. And there is another Field called State with two values as described above. Then try to filter the sum similar to this:

Sum( If(State = 'Input', Val, 0) )

or, may be you like below :

Sum( If State = 'Input', Val, Val*-1))

HtH

Roland