I don't have Excel available, but I'd used Defined Tables, and SUMIFS(), for this. On fly e.g.:
Define your table on sheet Mortgage as tMortgage. Let's assume the headers of Table columns are Date (column B), Mortgage (column C), and Budget (column F);
Add 2 columns as rightmost one to your table, with headers e.g. Year and Month;
Into any cell in Year and Month columns, enter the formulas
Code:
= YEAR([@Date])
= MONTH([@Date])
(Both columns will be filled with year and month numbers for matching Date in same row);
Now, in cell on any sheet you your formula, enter it like
Code:
=IF(SUMIFS(tMortgage[Budget], tMortgage[Year],2023,tMortgage[Month],1)=0,"", MIN($C$27-SUMIFS(tMortgage[Budget], tMortgage[Year],2023,tMortgage[Month],1),0))