How many different values appear in an Excel column? - excel

I have a column of repeated texts (companies) mapped to a column on whether a condition was met.
How do I count how many companies met the condition? For example the picture below should yield 2 (counting 1 for "Google" + 1 for "Apple" and 0 for "Sun")

Use this array formula:
=SUM(IF($B$2:$B$11="Y",1/COUNTIFS($A$2:$A$11,$A$2:$A$11,$B$2:$B$11,"Y")))
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} around the formula.

Related

Is there an excel formula that can check the number of words in consecutive cells and give an output based on conditions?

I am trying to create an output in excel based off the number of words in cells. Essentially i want to check if the sum of the words in 3 cells is = 1,2 or >=3. Im using the len formula which i have successfully used on single cell conditions but im struggling to create the formula that would check multiple cells.
Below is an example of my data:
Column A Column B Column C
Cat;dog Bird
Formula
=SUMIF(AND(LEN(TRIM(A4))-LEN(SUBSTITUTE(B4," ",""))+1, LEN(TRIM(C4))-LEN(SUBSTITUTE(C4," ",""))+1, >=3), "Titanium")
https://docs.google.com/spreadsheets/d/1W6nFr-W0r-XWZnvrFWndsvdBEEGHMQUa/edit?usp=sharing&ouid=103068518904190156690&rtpof=true&sd=true
First I made a single formula to work on a single cell. It ignores semicolons and commas to calculate total words. That formula is in column F and it's:
=IF(LEN(E5)=0;0;LEN(TRIM(SUBSTITUTE(SUBSTITUTE(E5;";";" ");",";" ")))-LEN(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(E5;";";" ");",";" "));" ";""))+1
Notice I added an IF to make sure that blank cells will count as 0 words (because the +1 will be added wrongly and we need to avoid this.
Now you just need to sum up all results and we get 8 words.
What you want is to get this result with a single formula and that can be perfomed with array formulas. In cell F11 my formula is:
=SUM(IF(LEN(E5:E8)=0;0;LEN(TRIM(SUBSTITUTE(SUBSTITUTE(E5:E8;";";" ");",";" ")))-LEN(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(E5:E8;";";" ");",";" "));" ";""))+1))
You need to introduce this formula pressing CTRL+ENTER+SHIFT or it won't work!
Now you got the result in a single formula and you just need to add your conditions mentioned in your post
UPDATE: In your Google Sheets, the correct formula would be:
=ArrayFormula(IF(SUM(IF(LEN(TRIM(A3:B3))=0,0,LEN(TRIM(A3:C3))-LEN(SUBSTITUTE(A3:C3," ",""))+1))>=3,"Good","Bad"))
Please, notice Excel is not the same as Google Sheets so sometimes the formulas may be different in one of them.

Excel: Count if cell is not empty using the "=" operator (allowing for a switch)

I want to create a switch for one of my criteria in a countifs-formula, using a dropdown list. For example:
I want to count all the companies that match criterion 1 (area), and then have a second criterion, size, whose value I can change using a dropdown list, and which can be set to "small", "big" or "both". The "both" part is where I can't figure out what to do.
With "limit values" on a cell (D1) that only allows 1 ("small") and 2 ("big"), and a reference to that cell, the first part is easy:
=countifs(A1:A10,"Munich",B1:B10,"="&D1)
What I'm wondering is what I would have to put into D1 that tells the function to count "all". Normally, you would simply use "<>" instead of "="&"..." to count all the non empty cells, but that's not an an option here. I tried putting * in D1 as well as ="*", but he won't recognize that (I gues due to the values being numbers and not text). I'm stuck.
Thanks for your help.
Edit:
For completenes' sake: I just tried to use the formula on a criterion where the data is text, not numbers, and in this case using an asterisk * works just fine. So if the column has "big" and "small" instead of "1" and "2" for values, and you put * into D1, it counts all non empty cells. Hooray :)
Use an IF on the outside that checks for the word "All":
=IF(D1="All",COUNTIF(A:A,"Munich"),COUNTIFS(A:A,"Munich",B:B,D1))
This array formula will do it also:
=SUM(COUNTIFS(A:A,"Munich",B:B,IF(D1="all",{1,2},D1)))
The formula needs to be entered with Ctrl-Shift-enter instead of Enter when exiting edit mode.

Array not outputting last cell

Following on from this question:
Array that outputs cells in a column AFTER a certain point
I have made a simplified example to test the formula
=IFERROR(INDEX($A$1:$A$11,SMALL(IF(ROW($A$1:$A$11)-MIN(ROW($A$1:$A$11))>MATCH("WORD",$A$1:$A$11,0),ROW($A$1:$A$11)-MIN(ROW($A$1:$A$11))),ROWS(A$1:A1))),"")
Here is my sample data In column A, and array formula in column B (Entered with ctrl + shift + enter)
:
The array is outputting the cells that are found after the WORD. However, you can see that 10 is not being displayed by the array.
I will display if I change all ranges in the formula to A1:A12, but this is not correct surely.
What is happening here?
You need to add 1 to the row output from the small, 11 - 1 = 10, So then you need to deal with the > Match by using >= MATCH:
=IFERROR(INDEX($A$1:$A$11,SMALL(IF(ROW($A$1:$A$11)-MIN(ROW($A$1:$A$11))>=MATCH("WORD",$A$1:$A$11,0),ROW($A$1:$A$11)-MIN(ROW($A$1:$A$11))+1),ROWS(A$1:A1))),"")
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} around the formula.

Return row number or true or false or value if condition is met - VBA Excel

I know this will sound odd, but is that scenario possible?
1st - I do not want to use a macro. So it has to be a formula.
Assuming I have this tree columns:
A B C
1 01-Jan-2016 05-Jan-2016 White
2 01-Feb-2016 08-Feb-2016 Yelllow
3 01-Mar-2016 09-Mar-2016 Red
Let's suppose I give this date: 03-Mar-2016. Do we have a way to return Red if that date is found on that range? Or at least return row number where that condition is met?
Use this array formula:
=INDEX($C$1:$C$3,MATCH(1,(E1>=$A$1:$A$3)*(E1<=$B$1:$B$3),0))
Being an array formula it needs to be confirmed with Ctrl _Shift_Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} around the formula.

Excel Index of Bottom Element in Column but > 0

I have column A that is full of numbers ranging from 0 to 100. How can I get the index of the bottom element, but which is bigger than 0.
For example
6
7
9
1
0
8
0
In this example the number returned should be "6", as it's the index of the cell that contains "8".
You want to use the array form of MATCH():
=MATCH(1E+99,IF($A$1:$A$7<>0,$A$1:$A$7))
Being an array it needs to be confirmed with Ctrl-Shift-Enter when exiting edit mode instead of Enter. If done properly excel will put {} around the formula.
This will find the last number in the range that is not 0.
If your list is not static, the list changes length, then you can use this formula which will grow and shrink as the data in column A changes:
=MATCH(1E+99,IF($A$1:INDEX(A:A,MATCH(1E+99,A:A))<>0,$A$1:INDEX(A:A,MATCH(1E+99,A:A))))
It is still an array and being an array it needs to be confirmed with Ctrl-Shift-Enter when exiting edit mode instead of Enter. If done properly excel will put {} around the formula.
Array formula's calculations are exponential and therefore we want to limit the size of the dataset being tested to the extents. The two INDEX(A:A,MATCH(1E+99,A:A)) find the last cell in Column A with a number and sets that as the last cell in the range.

Resources