David is correct. Subtotal may well suit you better.

If you want to stick with the SUMIF method, change the formula to:

=IF(AZ22=AZ23,"",SUMIF(AZ:AZ,AZ22,BJ:BJ))

Best regards, Rob.