best approach for calculating totals in datagrid

Hi, I’m a newbie on Mendix, trying to build a tiny invoicing app for learning purposes. My datamodel holds an invoice and invoiceline entity which are associated. My new/edit invoice page has a datagrid with the invoiceline as a datasource over an association with the invoice entity which is the page parameter. The attributes Amount, VAT and totals are each calculated by a seperate microflow, which is of course not very effective as I can’t find a way to calculate them in one single microflow. My other issue is that I can’t seem to find a way to calculate the invoice totals, thus a total for amount (without VAT), VAT and amount (with VAT). The easiest way is by using an aggrated function on the grid, but It won’t let me, even when I use an XPath as it’s still not possible. I get the error: aggregating on a calculated value is not possible. Could you give me a clue, how to handle this efficiently?
2 answers

Hi Roger,

   Instead of using a calculated attribute for the fields Amount, VAT, and Totals, I suggest you put a Before Commit event on your invoice line object that recalculates the totals for the Invoice entity.  This will do a rollup only when the information truly changes.  Calculated Attributes are recalculated every time that value is shown on the page, so you could be running that microflow a lot without the information changing.  This will also allow you to aggregate the invoice totals in a data grid.


Hi Roger, 

Instead of using calculated values, you could use a custom save microflow. By adding an action button with a microflow on your invoiceline new/edit page. In the microflow you calculate and store the values. 

Then you can use the aggregate option on the datagrid.