Is there a way to get the result from the Example sheet Columns J:K using a single function?
= is there a way to count unique / disctinct values within QUERY function, or any other single function that would create a pivot-like set of data with two columns?
In the example sheet I have a set of data, which I need to group by one column and count unique values in the other one. There's a workaround there, but it involves two formulas plus another one that would sort it properly (data set is growing and rows get added, so sorting manually is not the best option).
Query function (or, my knowledge of Query function) doesn't seem to be able to count unique values, so it's not working. Googling hasn't helped me much with this.
Since the data will grow, the idea is to avoid pivots here, and I'd need to update pivot filters all the time to list all new locations and have blanks excluded. Want to have it as automated as possible
UPD:
I found it! Thanks to ahab, works like a charm.
If two columns follow each other:
=ArrayFormula( SORT (QUERY( UNIQUE( TRIM(A:B) );
"Select Col1, count(Col2) Where Col1<>'' Group by Col1 Order by Col1
Label Col1 '', count(Col2) '' " ; 0), 2, FALSE)
If there're not needed columns between the two columns that you need:
=ArrayFormula( sort(QUERY( UNIQUE( QUERY( TRIM(C4:H) ,
"Select Col6, Col1 ") ) , "Select Col1, count(Col2) Where Col1<>''
Group by Col1 Order by Col1 Label Col1 '', count(Col2) '' " , 0), 2, FALSE))