0

I am working with a case similar to the following table:

Producto Referencia Cantidad
PRODUCTO 1 1001 35
PRODUCTO 1 1001 29

I am using the QUERY formula and I need the following result:

group by Producto count Referencia count unique Referencia sum Cantidad
PRODUCTO 1
PRODUCTO 2
PRODUCTO 3

Does anyone know how to do it?

1 Answer 1

1

Depending on your locale, try:

=arrayformula(query({A:C\if(countifs(A:A&"-"&B:B;A:A&"-"&B:B;row(B:B);"<="&row(B:B))=1;1;)};"select Col1,count(Col2),sum(Col4),sum(Col3) where Col1 is not null group by Col1 label Col1 'group by Producto',sum(Col4) 'count unique Referencia' ";1))

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot! What if the quantity column did not exist and I only wanted 'group by Producto', 'count Referencia' and 'count unique Referencia' columns?
=arrayformula(query({A:C,if(countifs(A:A&"-"&B:B,A:A&"-"&B:B,row(B:B),"<="&row(B:B))=1,1,)},"select Col1,count(Col2),sum(Col4) where Col1 is not null group by Col1 label Col1 'group by Producto',sum(Col4) 'count unique Referencia' ",1))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.