best approach for calculating totals in datagrid

0
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?
asked
2 answers
4

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.

answered
3

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. 

Best, 

Mitchel 

answered