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

Nested calculation using BigDecimal

I would like some help with the syntax of current expression that I am trying to use in a tXMLMAP expression:

(sort_APB_contr.TOT_BEDRAG_INCL_T_O__.subtract(sort_APB_contr.T_O_BEDRAG)).divide(sort_APB_contr.TOT_AANTAL_INCL_T_O__.subtract(sort_APB_contr.T_O_AANTAL))

I am getting the following error message:
"Exception in component tXMLMap_1
java.lang.ArithmeticException: Division undefined
    at java.math.BigDecimal.divide(Unknown Source)"

Basically what I would like to accomplish is the following calculation:
(sort_APB_contr.TOT_BEDRAG_INCL_T_O__ minus sort_APB_contr.T_O_BEDRAG) divided by (sort_APB_contr.TOT_AANTAL_INCL_T_O__ minus sort_APB_contr.T_O_AANTAL)

Thanks!

Kind regards
Dave

Labels (2)
4 Replies
JR1
Creator III
Creator III

Hi

This usually means that you are trying to divide by zero. You will need to catch this. Example (not tested):
sort_APB_contr.TOT_AANTAL_INCL_T_O__.subtract(sort_APB_contr.T_O_AANTAL) != (new BigDecimal(0)) ? (sort_APB_contr.TOT_BEDRAG_INCL_T_O__.subtract(sort_APB_contr.T_O_BEDRAG)).divide(sort_APB_contr.TOT_AANTAL_INCL_T_O__.subtract(sort_APB_contr.T_O_AANTAL)) : 0 (change to the value to be returned)


Let us know how this works out for you.

Regards,
Joachim
Anonymous
Not applicable
Author

JoRoesecke wrote:
Hi

This usually means that you are trying to divide by zero. You will need to catch this. Example (not tested):
sort_APB_contr.TOT_AANTAL_INCL_T_O__.subtract(sort_APB_contr.T_O_AANTAL) != (new BigDecimal(0)) ? (sort_APB_contr.TOT_BEDRAG_INCL_T_O__.subtract(sort_APB_contr.T_O_BEDRAG)).divide(sort_APB_contr.TOT_AANTAL_INCL_T_O__.subtract(sort_APB_contr.T_O_AANTAL)) : 0 (change to the value to be returned)


Let us know how this works out for you.

Regards,
Joachim

Hi Joachim,

Thanks for your quick reply.

I implemented your statement and got the following message:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    Type mismatch: cannot convert from Number&Comparable<?> to BigDecimal

Could this be caused by the part  "!= (new BigDecimal(0)) ?" of your statement?

Regards,
Dave
JR1
Creator III
Creator III

Yes, definitely. Try this:
((sort_APB_contr.TOT_AANTAL_INCL_T_O__.subtract(sort_APB_contr.T_O_AANTAL)).compareTo(new BigDecimal(0)) == 0) ? (sort_APB_contr.TOT_BEDRAG_INCL_T_O__.subtract(sort_APB_contr.T_O_BEDRAG)).divide(sort_APB_contr.TOT_AANTAL_INCL_T_O__.subtract(sort_APB_contr.T_O_AANTAL)) : 0 (change to the value to be returned)
Anonymous
Not applicable
Author

JoRoesecke wrote:
Yes, definitely. Try this:
((sort_APB_contr.TOT_AANTAL_INCL_T_O__.subtract(sort_APB_contr.T_O_AANTAL)).compareTo(new BigDecimal(0)) == 0) ? (sort_APB_contr.TOT_BEDRAG_INCL_T_O__.subtract(sort_APB_contr.T_O_BEDRAG)).divide(sort_APB_contr.TOT_AANTAL_INCL_T_O__.subtract(sort_APB_contr.T_O_AANTAL)) : 0 (change to the value to be returned)


Hi Joachim,

Tried this, but still got an error.

I've now added extra steps where I first filter (tFilterRow) out the '0' rows and in a second map I perform the calculation. This way I do not have to test for the division by 0 in my calculation.

Thanks once again for your assistance. Learned something new on adding tests in the calculations.

Regards,
Dave