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

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Use case for marital status

Hello,

 

I have one column for marital status having value:

 

Marital_status

M

S

D

 

and now i want,

 

Marital_status

married                           for M

single                              for S

Divorce                           for D 

Labels (2)
1 Solution

Accepted Solutions
ashif2
Creator II
Creator II

row1.MaritalStatus.equals("M")?
"Married":
row1.MaritalStatus.equals("S")?
"Single":
row1.MaritalStatus.equals("D")?
"Divorced":
"NA"

View solution in original post

7 Replies
ashif2
Creator II
Creator II

Use ternary operator.. Below is logic like: (Add null check , if the Marital status column is nullable )

 

Note: I assumed the datatype for the column MaritalStatus is character so i used equality operator, if the MaritalStatus is string use equals method(String handling ).. 

 

row1.MaritalStatus=='M'?
"Married":
row1.MaritalStatus=='S'?
"Single":
row1.MaritalStatus=='D'?
"Divorced":
"NA"

Anonymous
Not applicable
Author

Hello ,

 

 

It is "String" 

 

 

Thanks

ashif2
Creator II
Creator II

row1.MaritalStatus.equals("M")?
"Married":
row1.MaritalStatus.equals("S")?
"Single":
row1.MaritalStatus.equals("D")?
"Divorced":
"NA"

Anonymous
Not applicable
Author

Hello ashifa,

 

i tried that but its not workin, i have attached the screenshot of the function and the output of that.


a.png
b.png
Anonymous
Not applicable
Author

Are you sure about your Source Data ?

it's "M" or "M   " or "m"

you have to trim your data before, and i think there is a function like equalsIgnoreCase, or something like that.

 

Edit : Other thing : i see that your data is entoured by this character : '

Take Care ! You have to define in your tFileInputDelimited (Check CSV option), the entourage of your text. I think your String value must be like : "'M'" instead of "M"


Good luck,

 

SGV

Anonymous
Not applicable
Author

Thank you so much ...it's working 

Anonymous
Not applicable
Author

Looks like you're happy using Java code for this, but the tReplace component is often a much better choice for such things:

 

 

0683p000009LrAt.png

 

By default you don't need to worry about case sensitivity, but can enable it for each search/replace line if required, and it keeps the logic for your job visible, rather than hidden within more general components. It also has an advanced mode which allows the use of Regular Expressions, which are incredibly powerful should you need them.

 

Whenever possible, you should use components with specific functionality like this, rather than adding complex expressions in a tMap or code in a tJava component, as doing so means your job is largely self documenting, or at least much easier for someone new picking it up to read and understand the process you're automating. Good, well laid out and labelled jobs can also be useful when discussing things with non-technical people.