Drupal 10: How to do calculations with aggregated results of a row

64 views Asked by At

I'm using Views Aggregator Plus do aggregate the results of columns. However, I cannot do calculations with the result. This is because the module always does the aggregation last.

The aggregation groups several individual items that are the same and sums the numbers to a total. This then looks like this:

ITEM DEBIT CREDIT
Item A 213 213
Item B 157 722
Item C 489 100

What I want to achieve is that when both debit and credit have a result, they need to be substracted from each other (if debit is larger than credit: debit minus credit, if credit is larger: credit minus debit, if equal: 0).

Giving this:

ITEM DEBIT CREDIT DEBIT RESULT CREDIT RESULT
Item A 213 213 0 0
Item B 157 722 0 565
Item C 489 100 389 0

What solution would be best to tackle this problem? Can I achieve this with twig in views or templating? Or is the only solution to make a module?

0

There are 0 answers