Added support for getting count from advanced query