Просто переместите код сортировки
<?sort:ssFocusTypePrimary;'ascending';data-type='text'?>
перед кодом группировки.
<?sort:ssFocusTypePrimary;'ascending';data-type='text'?><?for-each-group:current-group()[xdoxslt:format_date(ssReportedDate, 'yyyy-mm-dd','mm/dd/yyyy', $_XDOLOCALE, $_XDOTIMEZONE)>= (xdoxslt:format_date($StartDate, 'yyyy-mm-dd','mm/dd/yyyy', $_XDOLOCALE, $_XDOTIMEZONE)) and (xdoxslt:format_date(ssReportedDate, 'yyyy-mm-dd','mm/dd/yyyy', $_XDOLOCALE, $_XDOTIMEZONE))<= (xdoxslt:format_date($EndDate, 'yyyy-mm-dd','mm/dd/yyyy', $_XDOLOCALE, $_XDOTIMEZONE)) and starts-with(ssRohClinicFacilityName,$Clinic) and ssVisitType=$VisitType];./ssFocusTypePrimary?>[![enter image description here][1]][1]