criteria builder and specification jpa

So, i'm pretty sure this is a basic mistake, but i can't reason what... I have a table with 20+ fields. I need to create a something to return a specific count from one field.

The select query is basically something like this:

SELECT d.host AS Host, COUNT(d.host) AS Total FROM VM_N d JOIN VM_VM h WHERE h.datetime BETWEEN 
CAST(#date1# AS DATE) AND CAST(#date2# AS DATE) GROUP BY d.host ORDER BY Total DESC

I have build a specification that filters dates as follow:

public static Specification<NSBaseQuery> withDateRange(Date dateInit, Date dateFim) {

    if (dateInit == null || dateFim == null) {
        return null;
    } else {//return a.compareTo(d) * d.compareTo(b) >= 0;
        return (Root<NSBaseQuery> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> cb.between(root.get("date"), dateInit, dateFim);
    }

}

but i'm struggling to create the select i'm pretty new to this...

This is all i could come with:

public static Specification<NSBaseQuery> getNSActives(Boolean active, Date dateInit, Date dateFim) {
    if (!active || active == null) {
        return null;
    } else {//root.get("host").alias("Host"), cb.count( root.get("host")).alias("Total")

        return (Root<NSBaseQuery> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            
            query.multiselect(root.get("host").alias("Host"), cb.count( root.get("host")).alias("Total"))
                    .where(cb.between(root.get("date"), dateInit, dateFim));
            //also here there's an error because of the return type that i can't resolve...
            
            
        };
    }

}

I how can i make this work?