I am trying to use COUNTIFS and SUMPRODUCT to count the number of unique text for a date within certain range for all rows.
For example, I would like to count the number of unique count for the items that are in February.
Date, Item Description, , Start, 2017-02-01
02/1/2017, abc, , End, 2017-03-01
03/2/2017, def
05/2/2017, abc
08/2/2017, def
01/3/2017, abc
05/3/2017, def
If I specify the range like this (i.e. from row 1 to 6), it does work and return 2.
=SUMPRODUCT((($A1:$A6>=$E1)*($A1:$A6<$E2))/COUNTIFS($B1:$B6, $B1:$B6, $A1:$A6, ">="&$E1, $A1:$A6, "<"&$E2))
However, if I specify the whole column it won't work and return 0.
=SUMPRODUCT((($A:$A>=$E1)*($A:$A<$E2))/COUNTIFS($B:$B, $B:$B, $A:$A, ">="&$E1, $A:$A, "<"&$E2))
Please suggest how can I fix this to do for all rows?
Probably more efficient to use an array formula with FREQUENCY, and that type of formula can cope with blank rows so you should just make the range large enough to cater for current data and possible future expansion, e.g. for data in rows 2 to 1000 you can use an array formula like this:
=SUM(IF(FREQUENCY(IF(A$2:A$1000>=E1,IF(A$2:A$1000<E2,MATCH(B$2:B$1000,B$2:B$1000,0))),ROW(B$2:B$1000)-ROW(B$2)+1),1))
confirm with CTRL+SHIFT+ENTER
You could use a dynamic named range e.g. Dates and enter this into the formula. It will then only evaluate for the required number of rows. Won't have the added luxury of barry houdini's answer which caters for blank cells in the range.
Ctrl + F3 will open the Name Manager and there you can click > New and enter Dates for the name and use a variation on the following formula for the Refers to:
=OFFSET(Sheet1!$A$2,0,0,COUNT(Sheet1!$A$2:$A$1048576),1)
The $A$1048576 is the last row in versions of Excel above 2003 and $A$65536 would be for before.
=SUMPRODUCT(((Dates>=$E1)*(Dates<$E2))/COUNTIFS(OFFSET(Dates,,1,,1), OFFSET(Dates,,1,,1), Dates, ">="&$E1, Dates, "<"&$E2))
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))
I have Twocolumns A, B ..I am trying to get the sum of A like below.
=SUMIFS(
sheet1!$A:$A,
sheet1!$B:$B, ("AB", "BC", "CD")
)
But this formula is not working.
Please suggest me.
Try to use following formula:
=SUMPRODUCT((sheet1!$B:$B={"AB","BC","CD"})*(sheet1!$A:$A))
or alternatively you can use an array formula:
=SUM(IF(sheet1!$B:$B={"AB","BC","CD"},sheet1!$A:$A,0))
enter formula in the formula bar and press CTRL+SHIFT+ENTER to evaluate it......
If I'm guessing your intention right, you should have:
=SUMIFS(sheet1!$A:$A,Sheet1!$B:$B,"AB")+SUMIFS(sheet1!$A:$A,Sheet1!$B:$B,"BC")+SUMIFS(sheet1!$A:$A,Sheet1!$B:$B,"CD")
Add two helper columns: in D:D you have the list of valid values. In C:C you have a formula like this (change ; to ,). In F1 you have your sum like this:
=SUMIFS($A:$A,$C:$C,FALSE)
Now you can add any number of valid criteria in column D:D.
You can use SUMIFS to return an array (one for each criterion) and then SUM to sum those, i.e.
=SUM(SUMIFS(sheet1!$A:$A,sheet1!$B:$B,{"AB","BC","CD"}))
This way retains the speed and efficiency of SUMIFS without needing repetition
If you have your criteria values in a range of cells you can simply reference the range, but use SUMPRODUCT to avoid "array entry"
=SUMPRODUCT(SUMIFS(sheet1!$A:$A,sheet1!$B:$B,Z2:Z4))
where Z2:Z4 contains the criteria
Note: in both of these SUMIFS does all the "heavy lifting" - SUM/SUMPRODUCT is used simply to sum the resulting array