Since you are using MySQL, I would approach by implementing in-line sqlvariables (via my first "from" alias. The @FirstOfThisMonth is computed by subtracting whatever the current day of month is from the current date (less 1).
Ex: Today is April 3rd (3rd day of month). So, -3 = March 31... PLUS 1 brings back to April 1 of current month. Once that date is determined, I can now subtract an entire month for first of PREVIOUS month (March 1st), and subtract 2 months for Feb 1st.
Now that this complexity is done ONCE, we can use these variables instead of constant datepart extraction for month and year. Especially if you consider trying to do two months ago from Feb 10th. (First of current is Feb 1, one month back is Jan 1, two months back is Dec 1 of prior year).
NOW, I simply SUM() based on a case when condition.
if the Invoice Date is >= @TwoMonthsAgo AND LESS THAN @LastMonth, that goes into the two-months-ago total.
the next is Invoice Date >= @LastMonth AND LESS THAN @FirstOfThisMonth for last month's total.
Now, you have a rolling two-month window... If you wanted to go longer, just add another monthly variable reference and SUM() its criteria.
Finally the WHERE clause can only include invoices that are greater or equal to the @TwoMonthsAgo so it doesn't have to go through the entire database
select
C.CustId,
SUM( CASE when I.InvoiceDate >= @TwoMonthsAgo AND I.InvoiceDate < @LastMonth
then Ia.Amount else 0 end ) as TotalTwoMonthsAgo,
SUM( CASE when I.InvoiceDate >= @LastMonth AND I.InvoiceDate < @FirstOfThisMonth
then Ia.Amount else 0 end ) as TotalLastMonth
from
( select @FirstOfThisMonth := date_add( now(), INTERVAL -dayofmonth(now())+1 day ),
@LastMonth := date_add( @myDate, INTERVAL -1 month ),
@TwoMonthsAgo := date_add( @myDate, INTERVAL -2 month )) sqlvars,
Invoice I
inner join InvoiceAmtSummary Ia
on I.GUIDInvoice = Ia.GUIDInvoice
inner join Customer C
on C.GUIDCustomer = I.GUIDCustomer
WHERE
I.InvoiceDate >= @TwoMonthsAgo
AND I.InvoiceDate < @FirstOfThisMonth
group by
C.CustID