I am not familiar with the design of this database solution but you probably have these relationships:
Where a portal to LIneItems on the Invoices layout is used to list each item sold on that invoice.
If so, you can set up a layout baed on the LineItems table that functions as a summary report producing the totals that you want. Much of what is done to produce the desired report will be done by finding and sorting the records.
For a tutorial on summary reports--which coincidentally is based on a line items table, see: Creating Filemaker Pro summary reports--Tutorial