Sorting Repeating Group by Referral Count

Hey everyone,

I’m trying to sort a Repeating Group based on the count of users associated with each item. In my setup, I have two data types: “User” and “Referral”. Each user can have multiple referrals.

My goal is to display referrals in descending order based on the number of pets referred by each referred user. Any tips on how to achieve this would be much appreciated! Note: it will be live search based on date range

Thanks!