Help with counting

Hi Folks, I’m looking for some help with counting. I have a collection name training_progrss with a reference field center_id that connects to the centers collection. My code below counts how many total trainings exist and how many total centers were trained. Then the next bit removes the dupe center_ids and fills the repeater with the names of the center. Each center shows once regardless of how many times they trained. This part all works great (with help from J.D. of course). Now I am trying to have an individual training count for each center in the repeater. My thinking is that I need to count how many times each center_id shows up before I remove dupes…?? I’m having a rough time figure out where to put the count. Every time I try all centers show 7 which is actually the total overall, not the individual totals. I hope this makes sense. Any advice, hints, links to specific api would be greatly appreciated.

export function filter_click(event, $w) {
$w( “#count” ).show();
$w( “#centers” ).show();

wixData.query( 'training_progrss' ) 
    .contains( 'trainer' , $w( "#staff" ).value) 
    .lt( 'training_date' , $w( '#toDate' ).value) 
    .gt( 'training_date' , $w( '#fromDate' ).value) 
    .count() 
    .then((num) => { 
        $w( "#count" ).text =  ''  + num; 
    }); 

wixData.query( 'training_progrss' ) 
    .contains( 'trainer' , $w( "#staff" ).value) 
    .lt( 'training_date' , $w( '#toDate' ).value) 
    .gt( 'training_date' , $w( '#fromDate' ).value) 
    .distinct( 'center_id' ) 
    .then((num2) => { 
        $w( "#centers" ).text =  ''  + num2.totalCount; 
    }); 

wixData.query( 'training_progrss' ) 
    .include( 'center_id' ) 
    .contains( 'trainer' , $w( "#staff" ).value) 
    .lt( 'training_date' , $w( '#toDate' ).value) 
    .gt( 'training_date' , $w( '#fromDate' ).value) 
    .find() 
    .then((results) => { 

let items = results.items;

        items = items.filter((e, i) => items.findIndex(q => q.center_id.title === e.center_id.title) === i); 
        $w( '#centersRepeater' ).data = items; 
        $w( "#centersRepeater" ).onItemReady(($item, itemData) => { 
            $item( "#center" ).text = itemData.center_id.title; 
            $item( "#url" ).text = itemData.center_id.subdomain; 
            $item( "#link" ).link = itemData.center_id.subdomain; 

// $item(“#centerTrainings”).text = ‘’ + results.totalCount; // this just shows 7 for all
console.log(itemData.center_id.title);
})
})

}

It’s not easy to understand what you’re trying to do.
Please explain in other words + emphasize the relevant chunk of code.