I want to count the number of cells that meet two conditions:
sheet ABC's A2:A100 should be equal to the value of sheet XYC cell A8
the cell value in range D2:M100 = 1
Originally, I tried to use this formula:
=COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$D$2:$M$100,1)
But this gave me error #VALUE
I then decided to use the following formula to count each column separately and add them together.
=COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$D$2:$D$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$E$2:$E$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$F$2:$F$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$G$2:$G$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$H$2:$H$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$I$2:$I$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$J$2:$J$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$K$2:$K$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$L$2:$L$100,1)+
COUNTIFS(ABC!$A$2:$A$100,XYC!A8,ABC!$M$2:$M$100,1)
I am wondering if there are any other ways that allows me to shorten my formula?
Thank you.
You can use a boolean structure inside SUMPRODUCT() or just SUM() if your version of Excel supports dynamic arrays (ms365):
=SUMPRODUCT((ABC!A2:A100=XYC!A8)*(ABC!D2:M100=1))
Related
Is there a way to calculate the count of items in a range, that are a formula?
I'm only expecting =TEXT formulas, so I tried =COUNTIF(1:1, "=TEXT"), but that didn't work. Seems CountIf only operates with the displayed values of the cells.
If I have understood your post clearly, specifically you need those functions which starts TEXT() then perhaps you could try :
• Formula used in cell F6
=SUM(N(IFERROR(LEFT(FORMULATEXT(D6:D19),6)="=TEXT(",0)))
If you have the following in cells A1:A5
=TEXT("493","DDD")
555
=TEXT("420000","YYYY")
Yep
Nope
Either of these formulas should give a result of 2
Counts formulas
=SUMPRODUCT(--ISFORMULA(A:A))
Counts Cells with Formula Text
=SUMPRODUCT(--ISNUMBER(SEARCH("text(",FORMULATEXT(A:A))))
Below is my Workbook Sheet1
Am expecting sheet2 like below,
Total Item column (Using countifs I can get but Sub_Item1,2 and 3 How do I use Match Index in Excel)
Use countifs to count total_item =COUNTIFS($A$3:$A$12,D3). For sub items use below formula. Then drag down and right as needed. If need to handle errors then use IFERROR() function.
=INDEX($B$3:$B$12,AGGREGATE(15,6,(ROW($A$3:$A$12)-ROW($A$2))/($A$3:$A$12=$D3),COLUMN(A$1)))
I want to get the count of cells used in an excel function.
For example say I have a sum function ='CV'!D11+Farmer!D11+'County'!D11+Rt!D11+WT!D11+'Country'!D11
I need a function that will tell me how many cells were used to get the total sum. In this case it is 6. The tricky part is if one of the cells used is blank I do not want it counted. For instance say cell D11 on the Farmer sheet is blank I do not want it counted in the total. So the total should be 5.
Use COUNT:
=COUNT('CV'!D11,Farmer!D11,'County'!D11,Rt!D11,WT!D11,'Country'!D11)
It will only count the cell if it has a number
You should really try to collate all your data in to a single sheet before running calculations. For the sake of example, I'll assume you have it in the range A1:A5, then you can add handling of the various cases using array formulas:
Get the count of non-empty cells (the ISBLANK function is untrustworthy in my experience): {SUM(IF(LEN(A1:A5)>0,1,0))}
Get the sum of those cells: SUM(A1:A5)
(must use Ctrl+Shift+Enter to enter the formula as an array formula, you will know it worked if the formula shows like {IF(...)} with the curly brackets)
Because blank/missing values are treated implicitly as 0 in the SUM function, this case is simple. If you have other validations then you'd have to write an array formula for the summation as well. For example, only including numbers between a min and max threshold (e.g. if you want to exclude outliers):
{SUM(IF(AND(A1:A5 >= yourMinValue, A1:A5 < yourMaxValue), A1:A5, 0)}.
If I understand your question correctly, you want to literately count the number of cells used in a formula which in your example is summing 6 values from 6 different locations.
I used the following example to demonstrate my solution:
The sum of =A1+B1+C1+D1+E1+F1 is 10 where cell C1 has a 0 value in it but cell E1 is blank.
Using the following array formula I was able to count the number of cells that have a value other than 0:
=SUMPRODUCT(IFERROR(ABS(N(INDIRECT(TRIM(MID(SUBSTITUTE(RIGHT(FORMULATEXT(A3),LEN(FORMULATEXT(A3))-1),"+",REPT(" ",100)),100*ROW(INDIRECT("1:"&LEN(FORMULATEXT(A3))))-99,100)))))>0,0)*1)
Please note you MUST press Ctrl+Shift+Enter upon finishing the formula in the formula bar otherwise they will not function correctly.
The logic is to use a combination of TRIM+MID+SUBSTITUTE+RIGHT+FORMULATEXT+REPT+ROW+INDIRECT to extract the cell addresses from the original formula, then use INDIRECT to convert the cell address into the values stored in those cells, then use a combination of IFERROR+ABS+N to find out if any of these values are not 0, and lastly use SUMPRODUCT to add up all the TRUE results.
It is obvious that there are a couple limitations of my solution:
If your actual formula is not strictly in the form of A+B+C+D+E+F, then my SUBSTITUTE part of formula will need further modification;
The formula will treat cells containing 0 as blank and does not include them in the count.
Let me know if you have any questions. Cheers :)
I want to check A1:A10 whether they are repeated themselves in A1:A10.
I know i can use this formula in B1 to B10.
Is it possible to simplify it by one formula?
=sumproduct(($a$1:$a$10=A1)*1>1)
=sumproduct(($a$1:$a$10=A1:A10)*1>1) ???
Yes you could try:
Formula in B1:
=SUMPRODUCT((COUNTIF(A1:A10,A1:A10)>1)*(1/COUNTIF(A1:A10,A1:A10)))
In this case there are two values that are repeated/have duplicates; Test3 and Test4.
In case your goal was only to count ALL rows that have duplicates (repeated values), you can use =SUMPRODUCT((COUNTIF(A1:A10,A1:A10)>1)*1) which in this case would give you 6.
EDIT
For multiple columns, replace COUNTIF with COUNTIFS and extend with the columns you want to compare:
Formula in C1:
=SUMPRODUCT((COUNTIFS(A1:A10,A1:A10,B1:B10,B1:B10)>1)*(1/COUNTIFS(A1:A10,A1:A10,B1:B10,B1:B10)))
If you have Office 365 with the new Dynamic Array functions (currently available in the insider build), you can use the Unique() function and compare a count of the range with a count of the unique values of the range.
=COUNTA(UNIQUE(A1:A10))<>COUNTA(A1:A10)
Read more about the new Dynamic Arrays here.
I was looking for a excel formula to do a task. Tried using Countif,Countifs. But with no luck. Any help is appreciated.
Task as below.
Type--------------Primary Color--------------Secondary Color
Car----------------Blue--------------------------Red
Bike--------------Black-------------------------White
Car---------------Blue--------------------------Blue
I need a formula which gives me a count of Cars having blue as their colour(Either Primary Or Secondary)
You can use following array formula (confirmed with Ctrl+Shift+Enter to calculate count of blue cars:
=SUM(N((B2:B4="Blue")+(C2:C4="Blue")>0)*(A2:A4="Car"))
or non array version:
=SUMPRODUCT(N((B2:B4="Blue")+(C2:C4="Blue")>0)*(A2:A4="Car"))
This part:
(B2:B4="Blue")+(C2:C4="Blue")>0
is an alternative way of expressing OR (not suitable for array formulas as it always returns a single value). N function converts boolean values to 0 and 1.
Edit: updated the formulas to include condition for A column.
What about adding a column with the following
=IF(OR(B1="Blue", C1="Blue"), 1, 0)
and copy that down.
On another sheet you can sum that new entire column with
=SUM(D:D)
Of course you will have a worksheet reference to the other sheet attached to the SUM formula.
If you don't want to do an array formula you can just do 2 countifs formulas (which are easier for people to read than array formulas)
=COUNTIFS(b8:b12,"Blue")+COUNTIFS(c8:c12,"Blue")