Rate calculation usecase

I have a simple use case that requires a bit of recursive logic; and since I am new to this, would really appreciate some help. Here is the logic for the calculation

Policy Amount - Premium Amount
$0-$100 $50 (Fixed Rate)
$101-$200 $75 (Fixed Rate)
$201-$300 Rate per $20 (or fraction thereof) is $5
Over $300 Rate per $10 (or fraction thereof) is $3

As per the table, here are a few examples
If the Policy Amount is $70, Premium will be $50 (Rule #1)
If the Policy Amount is $175, Premium will be $175 (Rule #2)
if the Policy Amount is $220, Premium will be $75 (Rule #2)+ 5*(220-200)/20 (Rule #3)=$80
if the Policy Amount is 350, Premium will be $75 (Rule #2)+ 5*(300-200)/20 (Rule #3)+3*(350-300)/10=$75+$25+$15=$115

Hi,

This is quite straight forward and you just about have the answer…Have a go at writing what you have written as a DMN table. The trick is, you should use a collect hit policy. Thus your policy amount may match one or more rules, accumulate the total based on the matched rules. You just need to write your equations in FEEL…

regards

Rob

1 Like

That is documented here https://docs.camunda.org/manual/7.14/user-guide/dmn-engine/feel/

Thanks, for the first 2 rules, it’s not collect but unique/first hit i think - for the rest of the rules, it is collect. Can we accommodate both within the same decision table?
Or are you suggesting the Rule #2 is modified as >100 so that it gets included in the collect hit policy?

Alternatively, can we not use a while loop in a BPMN and call the decision table recursively and keep adding the return values to a variable and output it?

Hi,

Yes, you may need to tune the rule criteria to support the collect hit policy.

Regards

Rob

Thank you Rob! Do you think the alternative approach is feasible too? any pointers on that please?

Hi,

yes your alternate is feasible, however IMHO potentially less elegant. I tend to like elegant solutions as in the long term they can be more maintainable…
regards

Rob

Thanks Rob, your inputs were really valuable, i was able to pull it off using only decision tables. Thanks again!

1 Like