For example, for year 2023, that formula should return sum of E3:E4, and when i drag down that formula, it should return, for 2022, sum of E5:E8.

=SUMIF(B2:B162, YEAR(B2)=2023, E2:E162)
I tied this formula for the year 2023 only, but this didnt returned the desired answer.
You can't use the
Year-function withinSumIfUse
Sumproductinstead like this:=SUMPRODUCT($E$2:$E$162 * (YEAR($B$2:$B$162) = H2))It will sum all cells from E whenever Year of accordin`g payment date equals the value from H2.