What does "I do not link the two by InvoiceID" mean?
If you have a parent to child, one to many relationship as is typical of Invoice----<LineItems in most invoicing solutions, then a Sum function defined in Invoices, not clients can compute a total based on all related LineItems for that invoice.
It's also possible to use a summary field defined in LineItems to display the same total, but I recommend using the sum function if you are putting this total on an Invoices layout where you enter or edit line item records as it will update more smoothly than the summary field.
'lines' is tracking time so when we do a project we enter the time and so on. at the end of the month (mostly) i will create an invoice that pulls to gather the line items in a given period.
I do this by creating a new invoice and entering a start date and end date that are 'invoice fields' there is a portal on the invoices layout that links to 'lines' it is filtered by line_date which has to be in the required range. it does that well ,but the sum(lines::cost) totals all the fields even the ones outside of the filter.
Use a relationship instead of a portal filter (you can use your two date fields with inequality operators in the relationship)
Use a summary field defined in the lines table and put it inside a one row portal with exactly the same portal filter.
I have just tried the relationship thing and it worked a treat thank you