Add ntile window function

Move this to top of method and change to :
```
if (totalCount < buckets) {
  return count;
}
```

Cleaner and avoids extra division