I need to review this query:
=QUERY('BD3'!A:Q, "SELECT D,Q, SUM(M) WHERE I='W34' AND M>0 AND L='Huacho' GROUP BY D,Q ORDER BY SUM(M) DESC LIMIT 5",-1)
I need to review this query:
=QUERY('BD3'!A:Q, "SELECT D,Q, SUM(M) WHERE I='W34' AND M>0 AND L='Huacho' GROUP BY D,Q ORDER BY SUM(M) DESC LIMIT 5",-1)
For the result you want, the correct SQL function should be:
RANK() OVER (PARTITION BY D, Q ORDER BY SUM(M) DESC
You can check this answer for detail explanations: Array Formula to Rank Column A Partition by Column B And C