Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Checkbox variable

Hello,

I have a table with a column that has positive and negative values. I use an expression to calculate the sum of this value.

Lets say Sum(Value). I want a checkbox that will include or exculde the negative values of this sum.

Can anyone help me please?

1 Solution

Accepted Solutions
johnw
Champion III
Champion III


antonopn wrote:Lets say the column "Value" has the following structure
VALUE
6
4
-1
What I would like is to calculate the Sum of this column, taking or not in account the negative values.
A checkbox is what I have thought. If it is checked the Sum would be 9. If not the sum would be 10.



antonopn wrote: Sorry but none of these two has helped. I am a newbie. I was expecting an expression like:
if(VALUE>0,sum(VALUE))


Did you even look at the two example applications you were given before saying they didn't help? Or since they weren't what you expected, did you just assume they didn't work? If you plug in your exact data, they give you the exact result you asked for. Here, I've done it for you. See the attached. There is a checkbox. If checked, the sum is 9. If not, the sum is 10. Exactly like you asked.

Just because a solution isn't what you expected doesn't mean it's wrong.

And if it isn't what you wanted, then you'll need to explain the question again, because everyone so far in the thread has interpreted what you said the same way, as best I can tell.

View solution in original post

9 Replies
Not applicable
Author

you need to use an if statement if(Value>0,sum(Value))

or else create a flag while loading the data

if(Value < 0, 'NEG','POS') as Value_Flag,

or create two new fields while loading the data and use these in a chart expression

if(Value < 0,Value) as Value_NEG,

if(Value > 0,Value) as Value_POS,

Not applicable
Author

Sorry but I am a newbie.

Lets say the column "Value" has the following structure

VALUE

----------

6

4

-1

----------

What I would like is to calculate the Sum of this column, taking or not in account the negative values.

A checkbox is what I have thought. If it is checked the Sum would be 9. If not the sum would be 10.

If there not a way through checkbox, please suggest another way.

Thank you for your time!!!

Not applicable
Author

There are several ways this could be done.

You could use a button with a macro to set a variable.

Then in the SUM statment check the variable to change the statment.

Such as:

If(vExcluder = 'Exclude',Sum(if(Value<0,null(),Value)),Sum(Value))

Attached is a simple example.

johnw
Champion III
Champion III

During the load, create a new field:

if(Value>=0,'Exclude Negative?') as "Exclude Negative?"

Create a list box for this field, don't show the caption, and on the Presentation tab, use a selection style override of Windows Checkboxes. Then just use a plain old sum(Value) for your expression. No macros. No actions. No fancy expressions.

See attached.

Not applicable
Author

Sorry but none of these two has helped. I am a newbie. I was expecting an expression like:

if(VALUE>0,sum(VALUE)) // by the way, this is not working...

So I could create two expessions.

1. Sum(VALUE)

2. if(VALUE>0,sum(VALUE))

Thanks

jonathandienst
Partner - Champion III
Partner - Champion III

Give this one a try:

sum(if(VALUE>0, VALUE))

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
johnw
Champion III
Champion III


antonopn wrote:Lets say the column "Value" has the following structure
VALUE
6
4
-1
What I would like is to calculate the Sum of this column, taking or not in account the negative values.
A checkbox is what I have thought. If it is checked the Sum would be 9. If not the sum would be 10.



antonopn wrote: Sorry but none of these two has helped. I am a newbie. I was expecting an expression like:
if(VALUE>0,sum(VALUE))


Did you even look at the two example applications you were given before saying they didn't help? Or since they weren't what you expected, did you just assume they didn't work? If you plug in your exact data, they give you the exact result you asked for. Here, I've done it for you. See the attached. There is a checkbox. If checked, the sum is 9. If not, the sum is 10. Exactly like you asked.

Just because a solution isn't what you expected doesn't mean it's wrong.

And if it isn't what you wanted, then you'll need to explain the question again, because everyone so far in the thread has interpreted what you said the same way, as best I can tell.

johnw
Champion III
Champion III

As far as giving you something closer to what you expected, we can use Jonathan's expression plus sum(Value) in an expression group, allowing you to cycle between the two expressions. That affects only one chart instead of all objects, though, so I'm not sure it's as complete a solution as what I posted, but it depends on what you want I guess. It also doesn't use a checkbox, which was your indicated preference. But it does what you asked in allowing you to include or exclude negatives, so there's a third option. See attached.

Edit: Oh, and if you do like this solution best, you might want to go with the below expression instead. It uses set analysis so may have higher performance. Worth testing if you have any performance issues, anyway.

sum({<Value*={">=0"}>} Value)

Not applicable
Author

Joh's solution is working with the checkbox.

I am a newbie and I did not understood how to use it in order to fill with my own data!

But with this stupidity of mine, I have found out that there are so many ways to do it!

Thank you ALL for your cooperation and patience!

problem solved!