Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

If statement issues in load script

Hello

I am having a few issues with an if statement in my load script.

I have a table from source with usernames where the username is blank.

I am applying an if statement evaluating any null values to have the value of 'Unknown' otherwise if the username is not null then give me the username. When I load the data in a chart table I am still getting empty values where I should be getting 'Unknown'. This causes anything else associated with the username being blank to be blank too.

The if statement I have used in my script is:

if(isnull(UserName) or UserName = '', 'Unknown', Username) as Username

I have also used a nested statement to see if I can overcome this issue which is:

if(isnull(UserName), 'Unknown',

     if(UserName = '', 'Unknown', UserName)) as UserName

After using the nested if statement I am still getting blanks in a straight table and a chart table.

Can anyone know what I am doing wrong or how to overcome this?

Thanks



1 Solution

Accepted Solutions
erichshiino
Partner - Master
Partner - Master

Hi,

You can simplify this with the following:

if( len(trim(UserName))=0, 'Unknown', UserName) as Username

But you problem maybe related to your data model.

Let us suppose that there is a table users and a table departments. If there is one department that is not associated with any user, some results will have departments but not users and that may be happening to you.

Hope this helps for now,

Regards,

Erich

View solution in original post

2 Replies
erichshiino
Partner - Master
Partner - Master

Hi,

You can simplify this with the following:

if( len(trim(UserName))=0, 'Unknown', UserName) as Username

But you problem maybe related to your data model.

Let us suppose that there is a table users and a table departments. If there is one department that is not associated with any user, some results will have departments but not users and that may be happening to you.

Hope this helps for now,

Regards,

Erich

Not applicable
Author

Hello Erich

Many thanks for the reply. I thought so but I will consider your code and try and use that in the future.

Thanks