Total Calculation

How to calculate the Sub Total to Total Amount
2 answers

Depends on your domain model.

But my guess is you have an order and orderline entity.

Retrieve all orderlines of the order from database and aggregate it with SUM function on orderlinevalue. This will lead to a SUM SELECT of orderlin values and return the SUM



In the Rapid developer course this and following lectures guides you on the calculation of the NrOfRegistrations

This logic is equal to an Order – Orderline situation, where instead of the Count aggregation the SUM aggregation should be used.


Option 1 the OQL-way

The best way, in terms of steps and in terms of performance is using OQL for this. To do this:

  • Import the module OQL into your project,
  • add activity of type java called ‘ExecuteOQLcommand’
  • as OQL command state:
    FROM YourModule.Order as o
    JOIN o/YourModule.Orderline_Order/YourModule.Orderline as ol
    GROUP BY o.Ordernumber
    SELECT o.OrderNumber, SUM(ol.TotalPrice)


  • add an entity to your domainmodel ‘OrderTotals’ having attributes ‘OrderNumber’ and ‘Total’, pass this entity to the second argument of the activity ‘ExecuteOQLCommand’.
  • Set ‘amount’, ‘offset’ and ‘store parameters’ to ‘empty’

See for a OQL playground including lots of useful examples.

Option 2 The Mendix way:

The best way in terms of readability for mendix-developers and easy-to-program is to do it in your microflow in two steps:

  1. retrieve the associated orderlines
  2. sum the orderline’s prices using activity ‘Aggregate list’


My advice is the first option. Ran a test