formula for comparing columns with tolerance in Excel - excel

I'm saerching for a formula comparing two columns f and g with h and i taking a tolerance into account. I have coordinates f and g and coordinates h and i and I want to know how often f equals or is simlar to h and g to i here with a tolerance of 2. But both criteria Need to be met for the Count.
I've tried things like this without succes:
=SUMPRODUCT((F:F=H:H)(G:G=I:I)(F:I>0))/4
=SUMMPRODUCT(((ABS(F:F)-(H:H)<=2))(ABS((G:G)-(I:I)<=2))(F:I>0))
COUNTIF didn't work at all.

With some random data I've made up this is working: assume F1:I6 are your coordinate pairs.
={SUM(IF((ABS(F1:F6-H1:H6)<=4)*(ABS(G1:G6-I1:I6)<=4);1;0))}
Enter as a matrix formula (Ctrl-Shift-Enter). The 4 stands for a tolerance of +- 2, adjust for your needs.
If you really have to cope with cells containing text within that range you need to test the cell first before subtracting:
{=SUM(IF((ABS(IF(ISTEXT(F1:F6);-9999;F1:F6)-IF(ISTEXT(H1:H6);-8888;H1:H6))<=4)*(ABS(IF(ISTEXT(G1:G6);-9999;G1:G6)-IF(ISTEXT(I1:I6);-8888;I1:I6))<=4);1;0))}
This looks ugly but it works. The formula substitutes a cell with text with a token value of -9999 or -8888. These values should never occur in the real data. I used 2 distinct values to cover the case where only 1 or both columns contain text. The difference of the values needs to be greater than the tolerance.

Related

SUMIF: formula as criteria not working for entire column

My worksheet contains orders from clients. The orders are all wooden panels.
Every order is assigned a number which is led by the letter Q.
Column B contains the number of parts in the order.
Column C contains the total m² in the order.
Orders that contain one or more parts that are 2.8 x 0.0735 m will get a row of their own.
I'm trying to count the number of times that this part occurs in a list of more than a thousand rows.
So if I divide the total m² by the m² of the part I'm looking for and divide this by the amount of parts in the order, I should get exactly 1 as a result.
If I take the sum of all the number of parts that result in a 1, I get my total.
Now I'd like to put this in one formula for the entire worksheet, but SUMIF doesn't work the way I'm trying. (It's in Dutch)
=SOM.ALS(B:B;(C:C/(2,8*0,0735)/B:B)=1)
I can't seem to use this formula as a criterium in the SUMIF.
For now I use a helping column that gives the right amount per row. Then take the total SUM of these.
Is it possible to put this in a single formula?
Yes, it is possible. Try this one:
{=SUM(--(B:B=C:C/(2.8*0.0735))*IF(ISERROR(1/B:B),0,1))}
Remember to enter it as an array function with CNTRL + SHIFT + ENTER.
The first half of the formula is just a logical test, after the asterisk it tests if 1/B results in an error (thereby omitting text, zeroes, and blanks) and returns a zero if there is an error.
These are then summed and the result displayed.
In Dutch and English:
{=SOMPRODUCT(--(B:B=(ALS(ISTEKST(C:C);1;C:C))/(2,8*0,0735));B:B)}
{=SUMPRODUCT(--(B:B=(IF(ISTEXT(C:C),1,C:C))/(2.8*0.0735)),B:B)}
is working perfectly. (Enter with Ctrl-Shift-Enter)
The first bit is the logical test, which will check if B:B = C:C / (2.8*0.0735)
It got stuck on #VALUE! because there is text in C:C.
The IF(ISTEXT)) eliminates text by converting them to numeric values, in this case 1, but it can be any numeric value.
The logical test will return TRUE(1) or FALSE(0) because of the double dash or unary operator and this will be multiplied by their respective B:B value.
Because the row with text has no value in B:B, it will result as zero.

Condensing nested if-statements with multiple criteria

The blue columns is the data given and the red columns is what is being calculated. Then the table to the right is what I am referencing. So, F2 will be calculated by the following steps:
Look at the Machinery column (D), if the cell contains LF, select column K, otherwise select column L
Look at the Grade column (E), if the cell contains RG, select rows 4:8, otherwise select rows 9:12.
Look at the Species column (A), if the cell contains MS, select rows 5 and 10, otherwise.......
Where every the most selected cell is in columns K and L, copy into column F.
Multiply column F by column C.
I don't want to make another column for my final result. I did in the picture to show the two steps separately. So column F should be the final answer (F2 = 107.33). The reference table can be formatted differently as well.
At first, I tried using nested-if statements, but realized that I would have like 20+ if statements for all the different outcomes. I think I would want to use the SEARCH function to find weather of not the cell contains a specific piece of information. Then I would probably use some sort of combination of match, if, v-lookup, index, search, but I am not sure how to condense these.
Any suggestion?
SUMPRODUCT is the function you need. I quickly created some test data on the lines of what you shared like this:
Then I entered the below formula in cell F2
=SUMPRODUCT(($I$4:$I$9=E2)*($J$4:$J$9=LEFT(A2,FIND(" ",A2)-1))*IF(ISERROR(FIND("LF",D2,1)),$L$4:$L$9,$K$4:$K$9))
The formula may look a little scary but is indeed very simple as each sub formula checks for a condition that you would want to evaluate. So, for example,
($I$4:$I$9=E2)
is looking for rows that match GRADE of the current row in range $I$4:$I$9 and so on. The * ensures that the arrays thus returned are multiplied and only the value where all conditions are true remains.
Since some of your conditions require looking for partial content like in Species and Machine, I have used Left and Find functions within Sumproduct
This formula simply returns the value from either column K or L based on the matching conditions and you may easily extend it or add more conditions.

Minimum value in a range, with multiple conditions

I have an Excel sheet:
A. B. C.
X. I. 10/10/2018 06:27:54
X. I. 12/10/2018 13:00:00
X. U. 12/10/2018 13:01:20
Y. I. 13/10/2018 13:05:40
Y. U 15/10/2018 07:22:23
Y. U. 17/10/2018 08:20:43
Column A is customer, Column B is activity, C is Start time.
How can get the maximum value (column C) of activity I for customer X?
using a standard formula that performs array like calculations
AGGREGATE
Use the following formula. Since it performs array like calculations, avoid using full column references like F:F as it can lead to a lot of unnecessary calculations.
=AGGREGATE(14,6,C1:C6/((A1:A6="X")*(B1:B6="I")),1)
Instead of hard coding your search values, you can set up the formula to search based on values in other cells. I used the following formula in the example below:
=AGGREGATE(14,6,C1:C6/((A1:A6=$E2)*(B1:B6=$F2)),1)
This answer assumes that your date time in column C is stored as number. If it is stored as a string it will need a modification to the formula in order to convert it to a numerical date for excel.
No need for complex AGGREGATEs or nasty array formulas.
A nice, simple MAXIFS will do what you want:
=MAXIFS($C$2:$C$7,$A$2:$A$7,$E$2,$B$2:$B$7,$F$2)
I would do this with an array formula (ctrl+shift+enter) :
=MAX((--(A1:A6="X."))*(--(B1:B6="I."))*(C1:C6))
Explanation:
the (A1:A6="X.") results in an array with TRUE/FALSE values where the condition is met;
the -- converts this in 1/0
the first * (array multiplication) gives an array with 1/0 where both conditions are met;
the second * gives an array with all values from column C that corresponds with the rows where both conditions are met;
the MAX results then in the maximum.
Just a tricky part with the dot behind the X and I. Not sure whether this is part of your data, if not you of course have to modify the condition. And instead of hard coding it in the formula, much better to work with cell reference.

Difference between 2 values in a row in excel formula

How to get this in excel
excel table
F column is the result column
For the following answer I am going to assume you only ever have two numbers in any row, but they can be in any cell along the row and they are always greater than 0.
If you just wish to find the difference between the two numbers without worrying about which number is bigger, a simple equation using maximum and minimum can be used, eg in Cell F1 you would have
=MAX(A1:E1)-MIN(A1:E1)
However, from your example, it seems more likely that you want to know the difference between the first number and the second number.
The difficulty here, is that the cells in columns B, C and D could contain either the first number, the second number, or no number! The solution is to use the following equation in Cell F1
=(MAX(A1:E1)-MIN(A1:E1))*IF(MAX(A1:E1)=INDEX(A1:E1,MATCH(0,A1:E1,-1)),-1,1)
This formula works as follows:
We still start off with the simple difference between the max and min, and then this is multiplied by 1 or -1 depending on which way around the numbers are.
MATCH(0,A1:E1,-1)
This part of the equation looks along the row for a 0, and assumes they are in descending order, so it will return the position of the second number.
This is then inserted into the INDEX function and checked to see if it is the same as the maximum number and the IF function returns either -1 or 1 as required.
Paste this formula on F1, then copy to F2 and F3
=INDEX(A1:E1,MATCH(TRUE,INDEX(A1:E1<>"",),0)) - LOOKUP(9.99E+307,A1:E1)

excel 'IF' 'OR' formula working but need blank option

I have successfully set up an 'IF' 'OR' formula that reviews the data of three cells and selects G unless one of the 3 cells contains an R in which case it displays R
=IF((OR('Jan 16'!B33="G",'Jan 16'!B34="G",'Jan 16'!B35="G")),"G","R")
The problem that I have is if there is no data populated into the logical test cells ('Jan 16'!B33, 'Jan 16'!B34 or 'Jan 16'!B35) the result is R. When the logical test cells contain no data I need the result to be blank.
Any help provided would be very much appreciated.
'IF' 'OR' formula that reviews the data of three cells and selects G
unless one of the 3 cells contains an R in which case it displays R
=IF((OR('Jan 16'!B33="G",'Jan 16'!B34="G",'Jan 16'!B35="G")),"G","R")
Alright, I'm not sure if that's what you meant to say or not, because right now, it is backwards. If any of the three cells contains a G, the formula will return G. All three cells would have to NOT contain G in order for it to return R. For example, even if you had data that was R|R|G, the formula would return a G (not R).
To get a formula as you've originally described, yet have it return blank if any of the three cells are blank, you could use this formula:
=IF(COUNTBLANK('Jan 16'!B33:B35)>0,"",IF(COUNTIF('Jan 16'!B33:B35,"R")>0,"R","G"))
To adjust your existing formula as you posted in your original question, you would use this:
=IF(COUNTBLANK('Jan 16'!B33:B35)>0,"",IF(COUNTIF('Jan 16'!B33:B35,"G")>0,"G","R"))
EDIT: Per additional requirement provided in comment:
Is there any way that I could add a third letter "Y"... so if in the
combination of three cells it is blank then return a blank, if in the
three cells there is an R return R, if in the three cells there is a Y
but no R then return Y and finally, if there are three G's return G
=IF(COUNTBLANK('Jan 16'!B33:B35)>0,"",IF(COUNTIF('Jan 16'!B33:B35,"R")>0,"R",IF(COUNTIF('Jan 16'!B33:B35,"Y")>0,"Y","G")))
Or if it specifically needs to look for 3x G:
=IF(COUNTBLANK('Jan 16'!B33:B35)>0,"",IF(COUNTIF('Jan 16'!B33:B35,"R")>0,"R",IF(COUNTIF('Jan 16'!B33:B35,"Y")>0,"Y",IF(COUNTIF('Jan 16'!B33:B35,"G")=3,"G","Invalid Data"))))

Resources