I've thought of a different approach, no math, for a simpler formula...
All months have at least 4 Sundays minimum. These are the only times months have 5 Sundays:
- first day of month is Sunday and the month has > 28 days.
- first day of month is Saturday and there are 30 or 31 days.
- first day of month is Friday or Saturday and there are 31 days.
So, 2 var statements (# of days and first day of month) then 'if' formulas to determine if it's 4 or 5 Sundays:
var number daysinmonth = Day(LastDayOfMonth([Your Date Field]));;
var number firstdow = DayOfWeek(FirstDayOfMonth([Your Date Field]));
If($firstdow=0 and $daysinmonth>28, 5,
$firstdow=6 and $daysinmonth>29, 5,
$firstdow=5 and $daysinmonth>30, 5, 4)