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

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to only do a decode if the field is not null

Hi I am currently using the code below for a decode but getting a null pointer when the value is null. Can someone let me know how I could check to see if the column is null before I do the decode. Below is my code

 

If not null then do below

(row1.PFR_REGION.equals("GULF"))?"3": (row1.PFR_REGION.equals("SF"))?"2": (row1.PFR_REGION.equals("QUEBEC"))?"6":row1.STATUS

Labels (2)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

You can just reverse the comparisons if you want row1.Status as the default value:

"GULF".equals(row1.PFR_REGION) ? "3" :
  "SF".equals(row1.PFR_REGION) ? "2" :
      "QUEBEC".equals(row1.PFR_REGION) ? "6" : row1.STATUS

Else, if you want an other default value, change the expression like this:

row1.PFR_REGION == null ? "YOUR DEFAULT VALUE" :
    "GULF".equals(row1.PFR_REGION) ? "3" :
        "SF".equals(row1.PFR_REGION) ? "2" :
            "QUEBEC".equals(row1.PFR_REGION) ? "6" : row1.STATUS

View solution in original post

2 Replies
TRF
Champion II
Champion II

You can just reverse the comparisons if you want row1.Status as the default value:

"GULF".equals(row1.PFR_REGION) ? "3" :
  "SF".equals(row1.PFR_REGION) ? "2" :
      "QUEBEC".equals(row1.PFR_REGION) ? "6" : row1.STATUS

Else, if you want an other default value, change the expression like this:

row1.PFR_REGION == null ? "YOUR DEFAULT VALUE" :
    "GULF".equals(row1.PFR_REGION) ? "3" :
        "SF".equals(row1.PFR_REGION) ? "2" :
            "QUEBEC".equals(row1.PFR_REGION) ? "6" : row1.STATUS
Anonymous
Not applicable
Author

Thanks very much it works!