Let me explain you solution logic;
1. first variable will hold monthstartdate of previous month
2. Second variable will hold the monthenddate of previous month
3. Third vaiable will hold the max date of the previous month date range
and then finally you can have sum of max date of previous month.
I used variable for this for simplicity and understanding..
Feel free if u still have confusion.
year(FinalDate) * 100 + month(FinalDate) as yearmonth,
year(AddMonths(FinalDate,-1))*100 + month(AddMonths(FinalDate,-1)) as previousyearmonth
(ooxml, embedded labels, table is Foglio1);
yearmonth as previousyearmonth,
max(FinalDate) as maxPrev
group by Type, yearmonth;
This code consider previous month only as you need ...
Hope it helps