Thanks for your help, @tony-brunsman ! I was able to solve the issue with the following code:
$w.onReady( function () {
$w( “#repeater1” ).onItemReady(($item, itemData) =>{
wixData.queryReferenced( “departmentposts” , itemData, “tags” )
.then( (results) => {
if (results.items.length === 0 ) {
$item( “#table1” ).collapse()}
else {
$item( “#table1” ).expand()
}
})})})