Fix order of inserts issue

This fixes the issue where inserting "by week" and then "by" would cause "by" not to be found