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

How to handle division by zero error in tmap.

Hi Team,

 

How to handle division by zero error in tmap.

 

src_cols

 

col1  integer

col2  integer

 

target_cols

col integer

 

after applying col1/col2 in tmap i am getting below error.

 

Exception in component tMap_1
java.lang.ArithmeticException: / by zero

 

Note: col1 and col2 we have 0(Zero) values.

 

Thanks

shree

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Great, would you accept the solution please? 

View solution in original post

3 Replies
Anonymous
Not applicable
Author

Assuming your expression is .....

row1.col1/row1.col2

...and assuming that if it is divided by 0 you want to return 0 (you can change this to whatever suits you), you can do this....

row1.col1==null || row1.col2==null || row1.col2.equals(0) ? 0 : row1.col1/row1.col2

I am also checking for nulls here, just in case.

Anonymous
Not applicable
Author

Hi @rhall,

 

I am tried below code,

 

row1.col1==null || row1.col2==null || row1.col2==0 ? 0 : row1.col1/row1.col2

because both are integer column type is integer.

 

It's worked for me.

 

thanks

Shree 

Anonymous
Not applicable
Author

Great, would you accept the solution please?