A1:200 B1:260
A2:300 B2:220
A3:400 B3:240
A4:200 B4:300
A5:200 B5:200
I got two tables going on and basically I want to check if row A is greater than 200 AND row B is greater than 250 then count.
So far I have this:
=COUNTIF(A1:A5,">= 200")
but I have no idea how to check if A passes then check B and if so, count it. I'm guessing something to do with IF, AND and maybe a for loop? I'm not familiar with this language at all :x
You want to calculate total count when column A is greater than 200 and B contains cell values greater than 250.
If you want a single value for entire table use countifs,
=COUNTIFS($A$1:$A$5,">200",$B$1:$B$5,">250")
If you want to get the counts in different column (let say C) on each row, then copy and paste below formula in C1 and drag it to C5 cell
=+IF(AND(A1>200,B1>250),1,0)
Where 1 means both conditions are true and 0 means either of condition is false.
However if you want to check first if the first condition is satisfying or not, then you can use below formula:
=+IF(A1>200,IF(B1>250,1,0),2)
Where "1" means true and both the condtion is satisfying , "0" means first condition is satisfying but second is not and "2" means the first condition is not satisfying hence it didn't check the second condition.
Hope this helps
Related
A
B
C
D
4
1
6
5649
3
8
10
9853
5
2
7
1354
I have two worksheets, for example column A in sheet 1 and columns B-D in sheet 2.
What I want to do is to take one value in Column A, and scan both columns B and C and it is between those two values, then display the corresponding value from column D in a new worksheet.
There could be multiple matches for each of the cell in column A and if there is no match, to skip it and not have anything displayed. Is there a way to code this and somehow create a loop to do all of column A? I tried using this formula, but I think it only matches for each row and not how I want it to.
=IF(AND([PQ.xlsx]Sheet1!$A2>=[PQ.xlsx]Sheet2!$B2,[PQ.xlsx]Sheet1!$A2<[PQ.xlsx]Sheet2!$C2),[PQ.xlsx]Sheet2!$D$2,"")
How do I do this?
Thank you.
I'm not positive if I understood exactly what you intended. In this sheet, I have taken each value in A:A and checked to see if it was between any pair of values in B:C, and then returned each value from D:D where that is true. I did keep this all on a single tab for ease of demonstration, but you can easily change the references to match your own layout. I tested in Excel and then transferred to this Google Sheet, but the functions should work the same.
https://docs.google.com/spreadsheets/d/1-RR1UZC8-AVnRoj1h8JLbnXewmzyDQKuKU49Ef-1F1Y/edit#gid=0
=IFERROR(TRANSPOSE(FILTER($D$2:$D$15, ($A2>=$B$2:$B$15)*($A2<=$C$2:$C$15))), "")
So what I have done is FILTEREDed column D on the two conditions that Ax is >= B:B and <= C:C, then TRANSPOSED the result so that it lays out horizontally instead of vertically, and finally wrapped it in an error trap to avoid #CALC where there are no results returned.
I added some random data to test with. Let me know if this is what you were looking at, or if I misunderstood your intent.
SUPPORT FOR EXCEL VERSIONS WITHOUT DYNAMIC ARRAY FUNCTIONS
You can duplicate this effect with array functions in pre-dynamic array versions of Excel. This is an array function, so it has be finished with SHFT+ENTER. Put it in F2, SHFT+ENTER, and then drag it to fill F2:O15:
=IFERROR(INDEX($D$2:$D$15, SMALL(IF(($A2>=$B$2:$B$15)*($A2<=$C$2:$C$15), ROW($A$2:$A$15)-MIN(ROW($A$2:$A$15))+1), COLUMNS($F$2:F2))),"")
reformatted for easier explanation:
=IFERROR(
INDEX(
$D$2:$D$15,
SMALL(
IF(
($A2>=$B$2:$B$15)*($A2<=$C$2:$C$15),
ROW($A$2:$A$15) - MIN(ROW($A$2:$A$15))+1
),
COLUMNS($F$2:F2)
)
),
"")
From the inside out: ROW($A$2:$A$15) creates an array from 2 to 15, and MIN(ROW($A$2:$A$15))+1 scales it so that no matter which row the range starts in it will return the numbers starting from 1, so ROW($A$2:$A$15) - MIN(ROW($A$2:$A$15))+1 returns an array from 1 to 14.
We use this as the second argument in the IF clause, what to return if TRUE. For the first argument, the logical conditions, we take the same two conditions from the original formula: ($A2>=$B$2:$B$15)*($A2<=$C$2:$C$15). As before, this returns an array of true/false values. So the output of the entire IF clause is an array that consists of the row numbers where the conditions are true or FALSE where the conditions aren't met.
Take that array and pass it to SMALL. SMALL takes an array and returns the kth smallest value from the array. You'll use COLUMNS($F$2:F2) to determine k. COLUMNS returns the number of columns in the range, and since the first cell in the range reference is fixed and the second cell is dynamic, the range will expand when you drag the formula. What this will do is give you the 1st, 2nd, ... kth row numbers that contain matches, since FALSE values aren't returned by SMALL (as a matter of fact they generate an error, which is why the whole formula is wrapped in IFERROR).
Finally, we pass the range with the numbers we want to return (D2:D15 in this case) to INDEX along with the row number we got from SMALL, and INDEX will return the value from that row.
So FILTER is a lot simpler to look at, but you can get it done in an older version. This will also work in Google Sheets, and I added a second tab there with this formula, but array formulas work a little different there. Instead of using SHFT+ENTER to indicate an array formula, Sheets just wraps the formula in ARRAY_FORMULA(). Other than that, the two formulas are the same.
Since FALSE values aren't considered, it will skip those.
I am trying to create a formula that checks Column A for unique values, then takes that value and checks column B for unique values and orders them sequentially in Column C. Column C is the where the formula goes. It's not in the actual data set.
This is what I want my data set to look like.
For example, I want to find unique Entry Number "123-A. I then want to look within that entry number and find the unique codes in Column B and order them sequentially. The first two are the same, so they both are sequence 1. Then the third row as a new code, "Y09", so it will get sequence 2. Once the next unique entry number is identified, I want to reset the sequential count. Thanks!
So, the first thing we want to do is check if a number has already been allocated. Since there are 2 columns to check, we need to use INDEX MATCH with an Array Condition instead of just a VLOOKUP:
INDEX($C$1:$C1, MATCH(1, ($A$1:$A1=$A2)*($B$1:$B1=$B2), 0))
These formula are intended for cell C2 - notice how we left the second cell in each Range reference without the $ to lock it in place. This means it will always stop at the row above the formula
If this works, we're done. If it doesn't we get an error - so, we can use IFERROR:
=IFERROR(INDEX($C$1:$C1, MATCH(1, ($A$1:$A1=$A2)*($B$1:$B1=$B2), 0)), ???)
On to replacing those question marks!
Since we don't have a match, we need to find the largest match for the Entry Number, and add 1 for it. If you have Office365 or Office2019, we can just use the MAXIFS function. Otherwise, we will have to use SUMPRODUCT and MAX to get the same result: (If the Entry Number does not exist, this will return 0)
MAXIFS($C$1:$C1, $A$1:$A1, $A2)
SUMPRODUCT(MAX($C$1:$C1 * ($A$1:$A1=$A2)))
Then, Add 1:
=IFERROR(INDEX($C$1:$C1, MATCH(1, ($A$1:$A1=$A2)*($B$1:$B1=$B2), 0)), MAXIFS($C$1:$C1, $A$1:$A1, $A2) + 1)
=IFERROR(INDEX($C$1:$C1, MATCH(1, ($A$1:$A1=$A2)*($B$1:$B1=$B2), 0)), SUMPRODUCT(MAX($C$1:$C1 * ($A$1:$A1=$A2))) + 1)
It appears that your data is already organized/sorted by the column A and B values. If this is the case, we can construct a formula implementing the following rules:
if the adjacent A and B values match the values above them, copy down the C value from above
if the adjacent A value matches the value above it, but the B value does not, then increment the C value from above.
If the A value does not the value above it, then set the C value to 1
In C2 enter 1. In C3 enter:
=IF(AND(A3=A2,B3=B2),C2,IF(A3=A2,C2+1,1))
and copy downward:
if your data is not organized in the same way your picture indicates, then ignore this solution.
TABLE + DESIRED RESULT
This is what I got but not sure why it doesn't work:
Formula entered in Sheet2!A2=
index($A$2:$A$100, match(0,if(OR(AND(now()-Sheet1!O2<1,D2="closed"),D2="Pending",""),0))
Show me the list of cells in Sheet1! when Condition 1: Now - Time in O2 < 1 Day & D2 = "closed"
Or Condition 2: D2 = "Pending"
Thanks for the help guys
Ok I think I got it, this is an array formula so you want to copy it into cell G2 and press CTRL+SHIFT+ENTER, then drag the formula down far enough to hold all the results. I changed the condition from "Open, waiting, pending or closed within the last 24 hours" to "not closed more than 24 hours ago" to make it easier to read
formula for G2 is:
=IFERROR(INDEX(A$2:A$11, SMALL(IF(NOT((C$2:C$11="Closed")*(NOW()-D$2:D$11>1)), ROW(A$2:A$11)-ROW(A$2)+1), ROWS(A$2:A2))), "")
The SMALL function looks like this =SMALL(array, n) and returns the nth smallest element of the array. In our case n is given by ROWS(A$2:A2) which will give the row number of the current row in the result output. i.e. the first row of your results will contain the 1st smallest number, the 2nd row will contain the 2nd smallest number etc, the trick is that its not giving the smallest number in the id list but its giving the smallest number in the array defined by this line:
IF(NOT((C$2:C$11="Closed")*(NOW()-D$2:D$11>1)), ROW(A$2:A$11)-ROW(A$2)+1
This part is a little complicated as its all array formulas/logic. Please note the * in this context represents a logical AND. If you want to understand it better you can highlight just this part of the formula in the formula bar in Excel and press F9, this will show the values of the array. Clicking in cell G2 and highlighting the line above gives this:
{1;FALSE;3;4;5;FALSE;FALSE;8;9;10}
You can see that the resulting array contains the row number for rows that meet the condition and FALSE for those who don't. The INDEX and SMALL functions then display the id of the row with the 1st smallest value then the second etc with the FALSE's used to ignore the rows that don't meet the condition.
syntax error
you have:
AND(now()-Sheet1!O2<1, D2="closed")
which is fine, problem is in your OR statement:
OR(AND(now()-Sheet1!O2<1,D2="closed"),D2="Pending","")
the last parentheses should be before the last comma I believe. Currently you have an OR statement with 3 arguments the last of which is "" which isn't going to give you what you want. I think you intended the "" to be the result of the IF statement not a condition for the OR statement, try this:
if(OR(AND(now()-Sheet1!O2<1, D2="closed"), D2="Pending"),"",0)
I can't get my head wrapped around this multi conditional between two columns. I have two columns A and B but would like to use some formulas to compare each "grouping" of column A. For example in Column A, if all "group 2" has all Column B values as Pass, it is a pass.
Edit: I've updated it with some more rules since this just a bit more complicated for me to wrap my head around.
There are only 5 criteria:
PASS, PROG, UNAVAIL, IGNORE, "BLANK"
Rules:
FAIL if subgroup has 1 or more fail
IGNORE if subgroup has 1 or more ignore
PASS if ALL PASS or combination of PASS and UNAVAIL
PROG if NOT fail and a combination of PASS, UNAVAIL, PROG
"BLANK"s are treated as UNAVAIL
Appreciate any help, thank you!
(Answer changed to reflect new criteria)
This sheet:
Was created with the following two formulas (using named ranges in A-C where the name is in the first row):
In C1 I entered (then copied)
=CONCATENATE(TRIM(A2),"-", IF(LEN(TRIM(B2)) > 0, TRIM(B2), "UNAVAIL"))
In F2 I entered (then copied)
=IF(COUNTIF(Tag, E2 &"-FAIL") >0, "FAIL",IF(COUNTIF(Tag, E2 &"-IGNORE") >0,"IGNORE",IF(COUNTIF(Group,E2) = COUNTIF(Tag, E2 &"-PASS") + COUNTIF(Tag, E2 &"-UNAVAIL"),"PASS","PROG")))
The 4th case is like an else at the bottom of a switch -- no need to explicitly check the condition.
along the same lines,
add a column C, where if the result is pass value is 0,
result is fail value will be -100000 or so (large negative)
for uncertain use some prime negative like -3/
then use a pivot table and use the sum of the values
Then you can use formulas to deduce different conditions.
the use of large negative number is to be be able to if all the results
are uncertain, as long as they don't overlap the range less than -100000 or so.
anyway you get the idea.
This formula may work (enter as an array formula CTRL-ENTER):
=IF(SUM(IF(IF($A$2:$A$23=$E2,$B$2:$B$23,"OUT_OF_GROUP")="FAIL",1,0))>0,"FAIL",IF(SUM(IF(IF($A$2:$A$23=$E2,$B$2:$B$23,"OUT_OF_GROUP")="IGNORE",1,0))>0,"IGNORE",IF(SUM(IF(IF($A$2:$A$23=$E2,$B$2:$B$23,"OUT_OF_GROUP")="PASS",1,0))+SUM(IF(IF($A$2:$A$23=$E2,$B$2:$B$23,"OUT_OF_GROUP")="UNAVAIL",1,0))+SUM(IF(IF($A$2:$A$23=$E2,$B$2:$B$23,"OUT_OF_GROUP")=0,1,0))=SUM(IF($A$2:$A$23=$E2,1,0)),"PASS","PROG")))
Here Group and Result are in $A$2:$A$23 and $B$2:$B$23, respectively. E2:E11 holds "s1" through "s10". I assumed Rule 3 meant that a combination of UNAVAIL and blanks is a PASS --- the logic could be modified to make that a PROG.
I need to count the number of unique items (here I have the names of organizations) in the excel-sheet...I used the following script but I cannot introduce multiple inputs to count all of them at once.
=SUMPRODUCT((A27:A128<>"")/COUNTIF(A27:A128,A27:A128&""))
I want to introduce, for instance, A27:A128, A145:A156 lists of cells to be checked and counted.
Does anyone know how I can count them? Is there another function to be called?
Very simple........use a "helper" column, say column D In D1 enter:
=A27 and copy down thru D102.
In D103 enter:
=A145 and copy down thru D114
Finally use:
=SUMPRODUCT((D1:D114<>"")/COUNTIF(D1:D114,D1:D114&""))
The formula you need looks like the following
=SUM( IF( MATCH(A27:A128,A:A,0)=ROW(A27:A128) , 1 , 0 ) ,
IF( MATCH(A145:A156,A:A,0)=ROW(A145:A156) , 1 , 0 ))
and works like this:
For every area you want to check you need the following construct:
IF( MATCH(A27:A128,A:A,0)=ROW(A27:A128) , 1 , 0 )
This tries to match every cell from A27 to A128 to the whole column A and checks, if the row where the value was found is equal to the current row. If this is the case, we found the first occurence, if it is a repeated occurence, the row will be smaller (because MATCH always returns the first row where the value was found). Now if we found a first occurence, IF returns 1, otherwise 0.
SUM just sums up every if (that means, if you have a third area and so on, just keep adding more IF-constructs and you're done), resulting in summing up a 1 for every first occurence of a value and a 0 for every follow-up - and you get your amount of unique values.
Attention: The whole formula is a matrix formula. After you put it in the cell, you must not end the editing with pressing ENTER but with STRG+SHIFT+ENTER simultaneously. This way excel surrounds the formula with {}-brackets that you cannot enter manually. It changes the way excel evaluates the formula and you might get an error if you try it as normal formula.
Also, as the values get checked against the whole column A the formula might or might not fail, if a certain value appears inside and outside of a checked area, depending on the ordering of the values.