Kept me nagging, I found a solution which I think works now.
You will need to fill a variable with the previous month end. You have to set in on the selection trigger of giorno and mese. Use Settings, Document Properties, Triggers, Field Event Triggers and the OnSelect action. It needs to set a variable vPrevMonth, it is filled with the trigger action (External, Set Variable), the Value formula is