Alert from port group by percentage

I have 10 ports in the TEST group. I can send an alert when all ports are in DOWN state. How do I create an alert that will send me an email when the number of ports with DOWN status exceeds, for example, 40%? I didn’t find any parameter for this.

If you switch to the advanced tab, you can see, that it’s SQL so you can calculate the percentage in your query.