The criteria_range
argument for the COUNTIFS
function generally needs to be a range
, and not an array. Hence your formula will fail.
You can use a Pivot table.
- Drag the
Group Number
to the rows area
- Drag
Date of Stop
to the Columns area
- Drag
Date of Stop
to the Values area
- Format as desired
For a formula solution, you can use SUMPRODUCT
. You have to exclude the first row, or add an additional criteria as text entries will result in a #VALUE!
error
E5: =SUMPRODUCT(($A$2:$A$200=$D5)*(MONTH($B$2:$B$200)=MONTH(E$4)))
Note that in your results table, the Date
row are real dates formatted to show as they appear.
Or, if your data is in a table, you can use structured references.
=SUMPRODUCT((Table1[[Group Number]:[Group Number]]=$D5)*(MONTH(Table1[[Date of Stop]:[Date of Stop]])=MONTH(E$4)))
Edit:
As an exercise, it is possible to use whole column references, as shown in the formula below which tests to ensure that the column B entries are dates.
However, this will significantly increase calculation times, and is rather inefficient. You are much better off avoiding this by:
- Excluding Row 1, or
- Using a dynamic range reference, or
- Using a
Table
with structured references
=SUMPRODUCT((IF(ISNUMBER(B:B),A:A,0)=$D5)*(MONTH(IF(ISNUMBER(B:B),B:B,0))=MONTH(E$4)))
Since this is an array formula, you need to "confirm" it by holding down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...}
around the formula as observed in the formula bar