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: 
jelly_gvm
Creator
Creator

If condition issue

Hi All,

below is my issue highlighted in red.

LOAD MESSAGE_CODE

     MESSAGE_DESC,

   if(Len(MESSAGE_CODE)>0, MESSAGE_DESC,MESSAGE_CODE)) as Details

FROM $(path)MESSAGE_CODES.qvd;

if the MESSAGE_CODE is exists then display MESSAGE_DESC dimension values else display MESSAGE_CODE dimension values, but it is displaying always MESSAGE_CODE dimension values in the report.

Can any one suggest me.

Thanks in advance.

Regards,

Ram

14 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

I see two problems - one in the question, and one in the suggested answers...

1. The way your IF statement is formulated, you want to use the Code when the Code value doesn't exist - so, every time the code value is NULL, you want to see NULL in your field. It sounds "upside-down" to me. Usually we ask "if this value is NOT NULL, then use it, otherwise use another value".

2. In the suggested solutions, people keep suggesting to use TRIM(LEN(...)), which is meaningless. The function len returns the Length of the field, which is a number. The function TRIM is only useful when it's applied to the field itself, not to its length. So, if anything, the following can be considered:

LEN(TRIM(Field))

This combination of the two functions will first trim the spaces on both ends of the field, and then calculate the length of the remaining value. The meaning is to treat any number of spaces the same way as empty strings.

cheers,

Oleg Troyansky

QlikView Your Business: An expert guide to Business Discovery with QlikView and Qlik Sense

jelly_gvm
Creator
Creator
Author

Thank you all, it's working for me and issue with the data.

Anonymous
Not applicable

HI Ram,

Does sunny's solution solves your issue?

jelly_gvm
Creator
Creator
Author

Thanks for your reply,

yes the Sunny's solution is working fine for me, if you have any other solution for this issue please share it.

Thanks &Regards

Ram

sunny_talwar

Hi Oleg

Thanks for pointing out the incorrect order of the Len() and Trim() functions. I have fixed the order in the above posts, so that anyone seeing the thread in the future doesn't get confused. and I recommend Ram‌ to make note of the change as well.

Best,

Sunny