I have a table that has Date, Type, and Item columns. Each string in the Item column is unique. I need to pivot this table so that each Item is sorted into a respective Type column.
I googled both Pivot Table function, and QUERY formula, both do not work with strings reliably. But maybe I simply cannot see a proper way.
Date | Type | Item |
---|---|---|
1 Jan 2020 | writing | pencil |
1 Jan 2020 | tool | hammer |
2 Jan 2020 | clothes | shoes |
2 Jan 2020 | writing | pen |
3 Jan 2020 | clothes | shirt |
3 Jan 2020 | clothes | trousers |
I want to turn it into this:
- | Clothes | Tool | Writing |
---|---|---|---|
1 Jan 2020 | hammer | ||
1 Jan 2020 | pencil | ||
2 Jan 2020 | shoes | ||
2 Jan 2020 | pen | ||
3 Jan 2020 | shirt | ||
3 Jan 2020 | trousers |
An approach using QUERY:
=arrayformula(query({row(A:A),A:C},"select Col2,max(Col4) where Col2 is not null group by Col1,Col2 pivot Col3",1))
Pivot/group by in query
always requires some form of aggregation to work; you can use min or max with strings and a column of unique values (derived in this instance from the row
function as your data does not contain a uniquely-valued column) to obtain the desired result.