# Expand Countifs Arrayformula in rows and columns

In this google sheet I have an array of Types and floors, The criteria rows and headers are auto populated by unique formulas.

I'm trying to create an array formula which will expand in the width (columns) and height (rows) infinitely, to lookup the count.

So instead of having an arrayformula in each cell in row 3, there will be just one in F3 Thanks,

• Welcome. Please remember that as per site guidelines when an answer addresses your question, accept it and even upvote it so others can benefit as well. Oct 2, 2020 at 1:18

Try this query:

`={Transpose(query(A3:B46,"SELECT count(A) GROUP BY B label count(A) 'Total'"));query(A3:B46,"SELECT A, count(A) GROUP BY A PIVOT B")}`

The formula consists of two queries:

• `Transpose(query(A3:B46,"SELECT count(A) GROUP BY B label count(A) 'Total'"))`
• this counts the number of "Floor" items for each "Type".
• Note inclusion of `transpose` to get the output to appear on a single row, and `label count(A) 'Total'` to generate an appropriate label for the row.
• `query(A3:B46,"SELECT A, count(A) GROUP BY A PIVOT B")`

Example output • This is a great solution. Oct 2, 2020 at 1:19