Count Unique Vaues with Criteria i.e. except some specific value - excel-formula

There are 4 criteria I need to follow in order to count column B "unique values".
Criterion 1: Column A should be equal to "Cat B".
Criterion 2: Column B should not be equal to "N/A".
Criterion 3: Column B should not be equal to "TBD".
Criterion 4: Column B should not start with "D".
How to solve this problem?
Sample:

You can use this array formula (click Ctrl + Shift + Enter together) to get your result:
{=SUM(IF(--($A$2:$A$36="Cat B")*--($B$2:$B$36<>"N/A")*--(LEFT($B$2:$B$36,1)<>"D")*--($B$2:$B$36<>"TBD"),1/COUNTIFS($B$2:$B$36,$B$2:$B$36,$A$2:$A$36,"Cat B",$B$2:$B$36,"<>N/A",$B$2:$B$36,"<>D*",$B$2:$B$36,"<>TBD")),0)}
Just a note that -- is to turn TRUE/FALSE to 1/0. It is easier to see in the Evaluate Formula window for debugging. But you can remove those dashes to make the formula shorter if needed.

Try countifs
=COUNTIFS(A2:A150;"Cat B";B2:B150;"<>N/A";B2:B150;"<>D*";B2:B150;"<>TBD")
Generic formula fro cells that do not contain certain text is : =COUNTIF(rng,"<>txt")

In Cell C2 enter below formula
=IFERROR(INDEX($B$2:$B$14,MATCH(1,INDEX(((COUNTIF($C$1:C1,$B$2:$B$14)=0)*($A$2:$A$14<>"Cat B")*($B$2:$B$14<>"N/A")*($B$2:$B$14<>"TBD")*(LEFT($B$2:$B$14,1)<>"D")),0,0),0)),"")
Drag/Copy down as required. Change range $A$2:$A$14 and $B$2:$B$14 as per your data range.
EDIT : To get count of unique PIN use
=SUMPRODUCT((A2:A845="Cat B")*(B2:B845<>"N/A")*(B2:B845<>"TBD")*(LEFT(B2:B845,1)<>"D")/COUNTIF(B2:B845,B2:B845))

Related

Find a match on two excel columns

I want to compare data between two tables on excel and get the cells that match in two columns.
i.e:
Look for the value from cell G9 in column A, if found the check if the value of cell J9 Equals to cell D of the row in which the first match was found.
I tried Vlookup, index and match, but I'm still missing a function to complete the syntax
=IF(VLOOKUP(G9,$A$9:$D$1127,1,FALSE),IF(J9=D,"","new"),"new")
I don't know what to insert instead of D
Sample: https://drive.google.com/open?id=1aJZlpQ2V-bmwmS1Kwk-OIiSvXR552JJH
You can use MATCH on an array premises. If you want the number of the line when the values of G9 and J9 occur on columns A:A and D:D simultaneously, use the formula:
{=IFERROR(MATCH(J9,IF(A:A=G9,D:D),0),"No Match")}
If you want to return just the word "new" in case of a valid match use:
{=IFERROR(IF(MATCH(J9,IF(A:A=G9,D:D),0)>0,"new",""),"")}
Don't forget to use Ctrl + Shift + Enter to place the braces on the formula.
EDIT:
Since I'm having some troubles with showing my solution, I'll be more thorough.
Let's imagine you have the following worksheet:
For each row in the first table, if you want to check a match on the second table, you could place the formula
{=IFERROR(IF(MATCH(A1,IF(E:E=B1,D:D),0)>0,"new",""),"")}
on cell C1 and drag it to the end (to C22 on my example). You will get the next result:
Please, don't forget to press Ctrl + Shift + Enter when you're entering the formula on cell C1.

Excel Formula to find the first higher value

In column D (Result), I would like to have the following formula.
For each Cell in column C, find in column B the first value higher than the value of the cell of column C (starting from the same row) and gives as output the difference between the values found in column A (Count).
Example:
the value in C2 is 40. the first cell of B that has a value higher than 40 is B6. So D2 takes A6.value - A2.value = 5 - 1 = 4.
Can it be done without the use of VBA?
It can easily be accomplished with an array formula (so you have to enter the formula with Ctrl+Shift+Enter ) :
{=MATCH(TRUE;IF(B2:$B$7>C2;TRUE;FALSE);0)-1}
Put this formula in cell D2, and just drag down. You only have to change the end of your data set (change $B$7 into the real last cell of the column with data)
The formula works as follows :
The IF statement results in an array with TRUE/FALSE values that meet your criteria : {FALSE;FALSE;FALSE;FALSE;TRUE;FALSE}
The MATCH (with the 0 switch) searches the array for the index of the first match, which is 5 in our case
And you have to subtract 1 to get the offset to the cell where the function is placed, so this gives you 4
So although you have to enter it as an array formula (you will get an N/A error without the ctrl+shift+enter), the result is just a single number.
Also, depending on your data set, you might want to add some ERROR handling in case no match has been found, e.g. just using the example data set in your question, the result in cell D5 will be N/A so you have to decide what value you want the result to be in such case.
And finally, I did not use the values in column A, as I assumed this is just a sequential ascending counter. If this is not the case, and you specifically want to find the difference between the corresponding values in that column, you can use the variant mentioned by Foxfire... in one of the other answers: =MIN(IF(B2:$B$6>C2;A2:$A$6))-A2
A slightly adjusted and shortened answer on Peter K.'s suggestion:
In D2:
=MATCH(TRUE,$B3:B$7>C2,0)
enter the formula with ctrl+shift+enter
Something like this should work for you. First transform your range to a table.
=IFERROR(AGGREGATE(15,6,--([#Second]<[First])*(ROW([#Second])<=ROW([First]))/--([#Second]<[First]*(ROW([#Second])<=ROW([First])))*[Count],1) - [#Count],"")
In this formula the comparison between [second] and [First] starts at the same row. That means that the value in D5 is 0 and not 1. (Like #Foxfire And Burns And Burnslike stated in the comments).
Ok, I did not post the answer waiting until OP answered why D5 is 1 instead of 0, but my formula is also an array formula. It would be:
=MIN(IF(B2:$B$6>C2;A2:$A$6))-A2
To type this formula in array mode, you need to type it as usual, but instead of pressing ENTER, you need to press CTRL+SHIFT+ENTER

How to do excel formula that would Sum values from column C if column A is 'X' or 'Y' and column B is 'Z'?

I have a spreadsheet from which I need to pick out some specific values that are in one of text columns but only if other column matches the year.
I have tried following SUM with IF but I think OR portion in textual column is failing...
=SUM(IF(B:B="*Nuoma*",B:B="*(Nuomininko)*",C:C=2016,D:D))
What I need is if in column B value contains Nuoma OR (Nuomininko) AND column C is 2016 then SUM column D...
Try,
=SUM(SUMIFS(D:D, B:B, {"*Nuoma*","*(Nuomininko)*"}, C:C, 2016))
The {"*Nuoma*","*(Nuomininko)*"} provides the OR to a wildcard match on Nuoma or a wildcard match containing (Nuomininko). You must wrap the SUMIFS in a SUM but no CSE is required.
Here's a suggestion based on the fact that in your example, both strings 'Nuoma' and 'Nuominiko' contain the same string 'Nuom'. It uses SUMPRODUCT and SEARCH (as a substitute for wildcards) together with a help column for the string matching.
Cell D7 in the screenshot contains this formula:
=IFERROR(SEARCH("Nuom",B7),0)
And the summation in E15 is done by =SUMPRODUCT(E6:E13,--(C6:C13=2016),--(D6:D13=1)). In my example this evaluates to the sum of cells E10 and E14: 4 + 2 = 6.
If you prefer to avoid the help column and use an array formula instead, this one produces the same result without involving column D (don't forget to do Ctrl + Shift + Enter):
{=SUMPRODUCT(E7:E14,--(C7:C14=2016),IFERROR(SEARCH("Nuom",B7:B14),0))}
I suppose it would be relatively straightforward to extended this to more complicated situations.

How to find the maximum value of a given range, dependent on the value in a separate column

Screenshot of the Excel worksheet
I'm working with historic stock prices, and using eight columns I have:
Column A: High
Column B: Low
Column C: Close
Column D: Cx-Cx-4
Column E: Counts the number of consecutive positive numbers in column D
Column F: Counts the number of consecutive negative numbers in column D
Column G: Calculate the difference between the maximum of column A and minimum of column B within a given sequence.
As an example G1 should equal:
=max(A1:A5)-min(B1:B5)
G6 should equal:
=max(A6:A8)-min(B6:B8)
G9 should equal:
=max(A9:A11)-min(B9:B11)
And so on.
I'd like to know if it is possible to automate this calculation, possibly with the use of one or more additional columns.
Welcome to SO!
This may not be the most efficient solution as you need to add two helper columns, but if I understand your requirements correctly, then this idea should work well enough.
First, let's assume that there are 100 rows in your data set. Given that, enter the formula "=A100" in cell G100 and the formula "=B100" in cell H100. This sets up the boundary condition for the formulas in columns G and H. Now, in cell G99, enter this formula:
"=IF(E99="",G100,IF(E100="",A99,MAX(A99,G100)))"
What this formula does is set up a "running maximum" with the following logic:
If the cell in E99 is blank, copy the running maximum from G100, else:
If the cell in E99 is not blank but the cell in E100 is, set up a new running maximum from the cell in A99, else:
Take the maximum of A99 and G100 as the new running maximum.
Similarly, copy the following formula into cell H100:
"=IF(F99="",H100,IF(F100="",B99,MIN(B99,H100)))"
This follows the same logic as the previous formula, but takes the minimum of column B.
Copy or autofill these formulas to the top of the data set. This should now give you running maximum for column A and a running minimum for column B.
The next step is to calculate the difference. I notice from your question, that you only seem to be interested in calculating this difference at the top of each range (G1, G6, G9, etc.), rather than doing it in every row. Given that, we need a slightly more complicated formula.
The boundary condition for this formula is simply "=G1-H1" entered in cell I1. In cell I2, enter this:
"=IF(OR(AND(E2<>"",E1=""),AND(F2<>"",F1="")),G2-H2,"")"
How this works is that it check two conditions that indicate a range boundary:
E1 is blank and E2 is not
or
F1 is blank and F2 is not
If either of these conditions hold, the IF statement is true and "G2-H2" is diplayed, otherwise a blank cell is displayed. Now copy or autofill this formula to the bottom of the data set.
As a final step, you can now hide columns G and H if you don't need them displayed. This should now give you the results I think you're looking for. Please let me know if this doesn't work out for you.

Excel, check if a column has the same amount of characters for each cell

I would like to add a check to my worksheet in Excel, to test if entries in a column have the same total number of characters. I know how to do it for two cells where I can simply use =IF(EXACT(LEN(A1),LEN(A2)),"Match","No Match") but what if I have a lot of cells to test against each other?
Example:
Add a helper column B with =LEN(A1), etc in each row, then a check cell in say C1 with =STDEV.P(B:B)=0. This will show TRUE if all entries in column A are the same length and FALSE otherwise.
Try this array formula (entered by holding down ctrl + shift while hitting enter):
=IF(AND(LEN(OFFSET($A$1,0,0,COUNTA($A:$A)))/LEN($A$1)=1),"Match","No Match")
or this normally entered formula:
=IF(AND(MMULT(LEN(OFFSET($A$1,0,0,COUNTA($A:$A))),1/LEN($A$1))=1),"Match","No Match")
You could also use the Std Dev calculation, as suggested by others, in an array (CSE) formula so as to avoid the helper column:
=IF(STDEV.P(LEN(OFFSET($A$1,0,0,COUNTA($A:$A)))),"No Match","Match")

Resources