"Group by" in DMN

I’ve been trying to design a process where one step will involve a decision. In order to make that decision, I need to calculate the total number of items (say invoices) belonging to a single person and only pick the all or some of them. As an example, pick all if the total number of item for that person is less than 4, and pick the ones with top 3 amounts if it exceeds 4…

The challenge is that we want to make such inputs (whether it is top 3, or if it exceeds 4 etc.) parametric to business users. Is that even a good use case for DMN?

My approach is that first applying “group by” with a script before the decision step and providing the grouped collection of items as a collection into the DMN model.

  1. If we provide the whole array in which all items are stored into the decision task, can grouping be done in the DMN as a sub-decision in a decision graph (to keep the BPM model simpler). Probably not with FEEL but how about with JS or Python as scripting language in that?
  2. After diving the whole array into subset of collections of items per person (like invoices grouped by person), how can we decide whether one particular item satisfies the rule in the first paragraph shown in italics?

Hi @IdemenB,

that is an interesting question!

I assume that the list looks similar to this:

{"invoices":[
  {"id":1, "person":"A", "amount": 10},
  {"id":2, "person":"A", "amount": 20},
  {"id":3, "person":"A", "amount": 30},
  {"id":4, "person":"A", "amount": 40},
  {"id":5, "person":"B", "amount": 15},
  {"id":6, "person":"B", "amount": 25}
]}

Yes, it should be possible to group the list in a required decision. Either with a script language or FEEL.

The FEEL expression could look like:

for p in distinct values(invoices.person) return invoices[person = p]

FEEL contains some built-in function that could be useful here:

Does this help you?

Best regards,
Philipp

1 Like