Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

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......

Thanks for your help

Annie

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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

View solution in original post

3 Replies
Anonymous
Not applicable
Author

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

Not applicable
Author

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

Not applicable
Author

Thank youn Jphannes, you made my day 😃