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: 
Anonymous
Not applicable

Max of Two Columns

Hello,

 

I am looking to get max of two column values as below. I have tried tjavarow and used the below syntax but it is throwing a null pointer exception. Any help will be appreciated.

 

output_row.MAX = Math.max(input_row.Col1,input_row.Col2);

<Col1><Col2>
19.25 
8.85 
12.43 
17.36 
17.36 
8.85 
11.9710.35
11 
Labels (3)
1 Solution

Accepted Solutions
akumar2301
Specialist II
Specialist II

Sorry it should be like this ( 3rd condition should be 1st)

input_row.Col2 == null && input_row.Col1 ==  null ? 0 :

input_row.Col1 ==  null ? input_row.Col2 :

input_row.Col2 == null ? input_row.Col1 :

input_row.Col1 >= input_row.Col2 ? input_row.Col1 : input_row.Col2

View solution in original post

5 Replies
akumar2301
Specialist II
Specialist II

 

input_row.Col1 >= input_row.Col2 ? input_row.Col1 : input_row.Col2

Anonymous
Not applicable
Author

Hi Abhilash Kumar,

 

I have tried this and I am still getting NullPointerException. any other work around ?

akumar2301
Specialist II
Specialist II

you could simply add null checks

 

input_row.Col1 ==  null ? input_row.Col2 :

input_row.Col2 == null ? input_row.Col1 :

input_row.Col2 == null && input_row.Col1 ==  null ? 0 :

input_row.Col1 >= input_row.Col2 ? input_row.Col1 : input_row.Col2

akumar2301
Specialist II
Specialist II

Sorry it should be like this ( 3rd condition should be 1st)

input_row.Col2 == null && input_row.Col1 ==  null ? 0 :

input_row.Col1 ==  null ? input_row.Col2 :

input_row.Col2 == null ? input_row.Col1 :

input_row.Col1 >= input_row.Col2 ? input_row.Col1 : input_row.Col2

Anonymous
Not applicable
Author

Thank you so much Abhishek. It has worked.