I've been Googling for hours trying to create a COUNTIFS formula that will:
count the unique records in a table range
that have dates that fall within 4 years after
a year in a referenced cell
This is what I have so far: =COUNTIFS(dte_degr_conferred2,"<="&YEAR('Student Success and Progress'!$G$1)+4) but it is not correct and I've tried several variations
Please note: dte_degr_conferred2 column contains dates, 'Student Success and Progress'!$G$1 contains a 4-digit year
Many Thanks
Perhaps you mean this array formula**:
=SUM(IF(FREQUENCY(IF(dte_degr_conferred2<>"",IF(YEAR(dte_degr_conferred2)='Student Success and Progress'!G1,dte_degr_conferred2)),dte_degr_conferred2),1))
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
Trying to work out exactly what you need (you might be overcomplicating). Here is an example of using the COUNTIFS formula to compare dates. This formula was entered into cell E6 with the setup as below:
=COUNTIFS($B$2:$B$6,"<="&E3+4,$B$2:$B$6,">="&E3)
I have an even more simplistic interpretation:
=COUNTIF(dte_degr_conferred2,">="&DATE('Student Success and Progress'!$G$1+4,1,1))
The "count unique" requirement makes this an interesting question.
Here's what I've come up with:
=SUM(
IF(
FREQUENCY(
IF((YEAR(ddc)>=ssp!$G$1) + (YEAR(ddc)<ssp!$G$1+4) = 2, ddc, ""),
IF((YEAR(ddc)>=ssp!$G$1) + (YEAR(ddc)<ssp!$G$1+4) = 2, ddc, "")
)>0,
1
)
)
... where ddc is dte_degr_conferred2 and ssp is 'Student Success and Progress'. (When posting to SO, it's helpful to reduce a question to its essentials, because that makes it easier to respond to, as well as making it more universally useful.)
Enter as an array formula: Ctrl + Shift + Enter
Example
In this example, there are three distinct dates that match the criteria: 05/12/2014, 09/12/2014, and 05/26/2012.
How it works:
When creating array formulas, it can be useful to work out the calculations separately before joining them in an array. I've done so here:
Column C is =(YEAR(A1)>=$B$1) + (YEAR(A1)<$B$1+4) (copied down). In Excel, TRUE is 1 and FALSE is 0, so you can add boolean values together. If A1 is between B1 and B1+4, both operands are TRUE, and TRUE + TRUE = 2.
Column D is =IF(C1=2,A1,"") (copied down). This grabs the data that matches the criteria. (I formatted as numbers to highlight the fact that Excel stores dates as numbers.)
Column E is =SUM(IF(FREQUENCY(D1:D10,D1:D10)>0,1)). For an explanation of this method, see http://office.microsoft.com/en-us/excel-help/count-occurrences-of-values-or-unique-values-in-a-data-range-HP003056118.aspx
My solution at top combines all this into a single array formula.
I have two columns, one "floor", floor can be written as an integer or a string "4-5" means 2 floors between 4F and 5F, then another is price, I need to "SUMPRODUCT" all the price for all floors.
I do not want to use hidden columns to help the calcuate, only one formula in the totle price cell.
have tried find,search,match,vlookup for this but get error #VALUE
this the formula I written in "find".
=SUMPRODUCT(K45:K59,(NOT(ISERROR(INT(H45:H59))))*1)+IF(AND(NOT(ISERROR(FIND("-",H45:H59))),NOT(ISERROR(INT(MID(H45:H59,1,FIND("-",H45:H59)-1)))),NOT(ISERROR(INT(MID(H45:H59,FIND("-",H45:H59)+1,LEN(H45:H59)))))),INT(MID(H45:H59,FIND("-",H45:H59)+1,LEN(H45:H59)))-INT(MID(H45:H59,1,FIND("-",H45:H59)-1))+1,0)
You can use SUMPRODUCT for this:
=SUMPRODUCT(
IF(ISNUMBER(H$45:H$59),
1,
MID(H$45:H$59,FIND("-",H$45:H$59)+1,10)-MID(H$45:H$59,1,FIND("-",H$45:H$59)-1)+1
),
I$45:I$59
)
Enter it as an array formula: Ctrl + Shift + Enter.
Output
I finally gave up the attempt of writing a single smart formula. because the row count of block is fixed, I divide the formula into a long-but-similar formula.
=(IF(AND(NOT(ISERROR(FIND("-",H45))),NOT(ISERROR(INT(MID(H45,1,FIND("-",H45)-1)))),NOT(ISERROR(INT(MID(H45,FIND("-",H45)+1,LEN(H45)))))),(INT(MID(H45,FIND("-",H45)+1,LEN(H45)))-INT(MID(H45,1,FIND("-",H45)-1))+1)*K45,K45))+(IF(AND(NOT(ISERROR(FIND("-",H46))),NOT(ISERROR(INT(MID(H46,1,FIND("-",H46)-1)))),NOT(ISERROR(INT(MID(H46,FIND("-",H46)+1,LEN(H46)))))),(INT(MID(H46,FIND("-",H46)+1,LEN(H46)))-INT(MID(H46,1,FIND("-",H46)-1))+1)*K46,K46))+(IF(AND(NOT(ISERROR(FIND("-",H47))),NOT(ISERROR(INT(MID(H47,1,FIND("-",H47)-1)))),NOT(ISERROR(INT(MID(H47,FIND("-",H47)+1,LEN(H47)))))),(INT(MID(H47,FIND("-",H47)+1,LEN(H47)))-INT(MID(H47,1,FIND("-",H47)-1))+1)*K47,K47))+(IF(AND(NOT(ISERROR(FIND("-",H48))),NOT(ISERROR(INT(MID(H48,1,FIND("-",H48)-1)))),NOT(ISERROR(INT(MID(H48,FIND("-",H48)+1,LEN(H48)))))),(INT(MID(H48,FIND("-",H48)+1,LEN(H48)))-INT(MID(H48,1,FIND("-",H48)-1))+1)*K48,K48))+(IF(AND(NOT(ISERROR(FIND("-",H49))),NOT(ISERROR(INT(MID(H49,1,FIND("-",H49)-1)))),NOT(ISERROR(INT(MID(H49,FIND("-",H49)+1,LEN(H49)))))),(INT(MID(H49,FIND("-",H49)+1,LEN(H49)))-INT(MID(H49,1,FIND("-",H49)-1))+1)*K49,K49))+(IF(AND(NOT(ISERROR(FIND("-",H50))),NOT(ISERROR(INT(MID(H50,1,FIND("-",H50)-1)))),NOT(ISERROR(INT(MID(H50,FIND("-",H50)+1,LEN(H50)))))),(INT(MID(H50,FIND("-",H50)+1,LEN(H50)))-INT(MID(H50,1,FIND("-",H50)-1))+1)*K50,K50))+(IF(AND(NOT(ISERROR(FIND("-",H51))),NOT(ISERROR(INT(MID(H51,1,FIND("-",H51)-1)))),NOT(ISERROR(INT(MID(H51,FIND("-",H51)+1,LEN(H51)))))),(INT(MID(H51,FIND("-",H51)+1,LEN(H51)))-INT(MID(H51,1,FIND("-",H51)-1))+1)*K51,K51))+(IF(AND(NOT(ISERROR(FIND("-",H52))),NOT(ISERROR(INT(MID(H52,1,FIND("-",H52)-1)))),NOT(ISERROR(INT(MID(H52,FIND("-",H52)+1,LEN(H52)))))),(INT(MID(H52,FIND("-",H52)+1,LEN(H52)))-INT(MID(H52,1,FIND("-",H52)-1))+1)*K52,K52))+(IF(AND(NOT(ISERROR(FIND("-",H53))),NOT(ISERROR(INT(MID(H53,1,FIND("-",H53)-1)))),NOT(ISERROR(INT(MID(H53,FIND("-",H53)+1,LEN(H53)))))),(INT(MID(H53,FIND("-",H53)+1,LEN(H53)))-INT(MID(H53,1,FIND("-",H53)-1))+1)*K53,K53))+(IF(AND(NOT(ISERROR(FIND("-",H54))),NOT(ISERROR(INT(MID(H54,1,FIND("-",H54)-1)))),NOT(ISERROR(INT(MID(H54,FIND("-",H54)+1,LEN(H54)))))),(INT(MID(H54,FIND("-",H54)+1,LEN(H54)))-INT(MID(H54,1,FIND("-",H54)-1))+1)*K54,K54))+(IF(AND(NOT(ISERROR(FIND("-",H55))),NOT(ISERROR(INT(MID(H55,1,FIND("-",H55)-1)))),NOT(ISERROR(INT(MID(H55,FIND("-",H55)+1,LEN(H55)))))),(INT(MID(H55,FIND("-",H55)+1,LEN(H55)))-INT(MID(H55,1,FIND("-",H55)-1))+1)*K55,K55))+(IF(AND(NOT(ISERROR(FIND("-",H56))),NOT(ISERROR(INT(MID(H56,1,FIND("-",H56)-1)))),NOT(ISERROR(INT(MID(H56,FIND("-",H56)+1,LEN(H56)))))),(INT(MID(H56,FIND("-",H56)+1,LEN(H56)))-INT(MID(H56,1,FIND("-",H56)-1))+1)*K56,K56))+(IF(AND(NOT(ISERROR(FIND("-",H57))),NOT(ISERROR(INT(MID(H57,1,FIND("-",H57)-1)))),NOT(ISERROR(INT(MID(H57,FIND("-",H57)+1,LEN(H57)))))),(INT(MID(H57,FIND("-",H57)+1,LEN(H57)))-INT(MID(H57,1,FIND("-",H57)-1))+1)*K57,K57))+(IF(AND(NOT(ISERROR(FIND("-",H58))),NOT(ISERROR(INT(MID(H58,1,FIND("-",H58)-1)))),NOT(ISERROR(INT(MID(H58,FIND("-",H58)+1,LEN(H58)))))),(INT(MID(H58,FIND("-",H58)+1,LEN(H58)))-INT(MID(H58,1,FIND("-",H58)-1))+1)*K58,K58))+(IF(AND(NOT(ISERROR(FIND("-",H59))),NOT(ISERROR(INT(MID(H59,1,FIND("-",H59)-1)))),NOT(ISERROR(INT(MID(H59,FIND("-",H59)+1,LEN(H59)))))),(INT(MID(H59,FIND("-",H59)+1,LEN(H59)))-INT(MID(H59,1,FIND("-",H59)-1))+1)*K59,K59))