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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

if statement

Hi all,

i am trying to build a field based on other fields' values during the LOAD of a table:

// number sec IV answered

          if ([4_1a_Answered] = 1, 1 +

                         if ([4_1b_Answered] = 1, 1 +

                                        if ([4_1c_Answered] = 1, 1 +

                                                       if ([4_1d_Answered] = 1, 1, 0

                                                       ))))                                                                                                                                                                          as [Number Sec IV answered],

The problem is that it does not work, if one ore more *_*_Answered fields are not 1. (If they are <> 1, i would just like to not count them (they can either be 1 or 0).

Thanks for some advise.

K

1 Solution

Accepted Solutions
Not applicable
Author

Thanks.

I tried a

RangeSum([4_1a_Answered], [4_1b_Answered], [4_1c_Answered], [4_1d_Answered]) as [Number Sec IV answered]

that seems to work fine.

View solution in original post

5 Replies
Not applicable
Author

Anyone ? please..

Not applicable
Author

Have you tried seperating them into several if statments?

if ([4_1a_Answered] = 1, 1 )

+

if ([4_1b_Answered] = 1, 1 )

+

if ([4_1c_Answered] = 1, 1)

+

if ([4_1d_Answered] = 1, 1)

                                   as [Number Sec IV answered],                

However this may not work either as I am not sure how it will handle the nulls with adding. Can also try this:

if ([4_1a_Answered] = 1, 1,0 )

+

if ([4_1b_Answered] = 1, 1 ,0)

+

if ([4_1c_Answered] = 1, 1,0)

+

if ([4_1d_Answered] = 1, 1,0)

                                   as [Number Sec IV answered],    

Not applicable
Author

Thanks.

I tried a

RangeSum([4_1a_Answered], [4_1b_Answered], [4_1c_Answered], [4_1d_Answered]) as [Number Sec IV answered]

that seems to work fine.

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

The problem is that 1 + Null() = Null(). You can use the Alt() statement to ensure that your addition works.

1 + Alt(Null(), 0) = 1

So use multiple If statements as marcsliving suggested, but wrap each with Alt(...., 0) so that if it is missing or null, then it will return 0.

Regards

Jonathan

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

Hi

Yes Rangesum handles nulls as 0 so it will work.

Regards

Jonathan

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