Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
pnn44794
Partner - Specialist
Partner - Specialist

Help Getting Even Number For Result

Hello:

I need a little bit of help with an expression I'm trying to create that will return an Even number when the result is odd by simply adding 1 (one) to the result, otherwise, leave the result as is if it's already an even number.  For example, if the result is 3, I want to add 1 to it in order to make it 4, if result is 7 add 1 to make it 8, if result is 10, leave it as 10.

The expression I'm trying but which has some type of error (guessing a syntax error) is the following:

=If(Odd(Sum(CPU2) / Count([Host Name])), =Sum(CPU2) / Count([Host Name]) +1)

I think I'm close, and just missing something simple or so I hope.  As always, thanks in advance for any and all help and responses.

1 Solution

Accepted Solutions
Nicole-Smith

To change your expression so it always returns an even number, wrap it in Round(x, 2):

Round(Sum(CPU2) / Count([Host Name]), 2)

View solution in original post

4 Replies
Digvijay_Singh

'=' in the middle might be giving syntax error -


=If(Odd(Sum(CPU2) / Count([Host Name])), Sum(CPU2) / Count([Host Name]) +1)

pnn44794
Partner - Specialist
Partner - Specialist
Author

Hello Digvijay:

Thanks for the response. You’re right.  Removing the “=” in the middle did indeed fix the syntax error. Thanks for that.

When the expression executes though after saving the update, I get no results.  I get an empty table like the following:

 

If I change the expression to Sum(CPU2) / Count([Host Name]), I get the following table.  I'm not worried about the N/A's at the moment.  I'll clean them up later.  I'm wanting the 3's to be 4's and the 21's to be 22's.

As an FYI, I won't be able to look at this again, most likely, until tomorrow.

 

 

Nicole-Smith

To change your expression so it always returns an even number, wrap it in Round(x, 2):

Round(Sum(CPU2) / Count([Host Name]), 2)

pnn44794
Partner - Specialist
Partner - Specialist
Author

Hello Nicole:

Wow.  So simple.  I was obviously thinking I needed to use the Odd function and another Sum expression, but your solution is so much more simple.  I was over-complicating it.  One of these days, I'll know the correct functions to use.  There's a lot of them, but that's part of the power of Qlikview.

Thank you very much for your help.  It is appreciated.  I will mark your answer as correct.  Thanks again.