average attribute of empty team

I am trying to match to teams by average rating with a rule like this:

{"name": "EqualTeamSkills",
"description": "The average skill of players in each team is within 100 points of each other",
"type": "distance",
"measurements": [ "avg(teams[teamA].players.attributes[rating])" ],
"referenceValue": "avg(teams[teamB].players.attributes[rating])",
"maxDistance": 100}

In the worst case scenario when there is only one player online this rule always fails.

But if I switch teams in measurement and referenceValue making sure that team in referenceValue is not empty single player will match.

As I understand there was a similar question: https://forums.awsgametech.com/t/flexmatch-express-fair-team-rating-rule-with-perhaps-empty-teams/3848/1 a year ago.

Is there a more correct way to match single player with equals team skill rule like this?

It seems to me that avg([]) is a valid value for measurements but not for referenceValue. Am I correct?

Yes you are correct. Distance rule has to be distance to something. That something is the referenceValue, which can NEVER be empty. An alternative that should either work or be very close to something that does.

    {"name": "EqualTeamSkills",
"description": "The average skill of players in each team is within 100 points of each other",
"type": "distance",
"measurements": [ "min(avg(teams[*].players.attributes[rating]))" ],
"referenceValue": "max(avg(teams[*].players.attributes[rating]))",
"maxDistance": 100}

This computes a per-team average rating and then compares min vs max, which should always work.