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: 
Not applicable

Check if field is null in script, in conditional statement

Hello,

I want to check if a value is Null, and if it is Null, I want to assign a value. This is what im trying:

if(IsNull([Stock]), [Stock] = 1, [Stock]) as [Stock]

Problem is, when I check the value the [Stock] = 0. So instead of making it 1 its 0.

How can I do this different?

1 Solution

Accepted Solutions
Not applicable
Author

if([Stock]=' ',  1, [Stock]) as [Stock]

View solution in original post

5 Replies
Sokkorn
Master
Master

Hi,

Did you try something like this yet:

If(IsNull([Stock]),0,[Stock])     AS [Stock],

Or If(Len([Stock])=0,0,[Stock])     AS [Stock],

Regards,

Sokkorn

Not applicable
Author

All the non-null values turn into -1 for some reason when I use this.

Sokkorn
Master
Master

Hi,

Does your [Stock] field have null value or not? And if [Stock] is null then what value you want to assign?

Regards,

Sokkorn

Not applicable
Author

if([Stock]=' ',  1, [Stock]) as [Stock]

Not applicable
Author

Thanks alot! this worked for me. But instead of [Stock]=' ' I could use IsNull([Stock]). But just putting 1 in the second field worked.