If DeliveryDt contains (will possibly ever contain) a time portion (the data type DATETIME would allow that) then the condition
And DeliveryDt <= '$LASTDAYOFMONTH'
will omit all deliveries from the $LASTDAYOFMONTH.
Always use And DeliveryDt < @FirstDayOfNextMonth
_____________
Code for TallyGenerator