Kibana query problem

KQL is a filtering language, you can't run aggregations. I am afraid what you want is not possible with Lens formulas.