Excel count columns where values match and value is above threshold - excel

Im trying to find matches between column B and C when the value in A is above a certain threshold.
0.99 p269 p269
0.99 p312 p312
0.64 p249 p249
0.64 p247 p247
0.09 p243 p284
I'm trying the Countifs method but it doesnt work.
=COUNTIFS(
A1:A31968,">" & F2,
B1:B31968,C1:C31968
)
The first part works (F2 is my treshold), but the I want to check all rows.
So when my threshold is 0.5 I want 4 as a result. When the threshold is 0.08 I still want 4 because the labels of the fifth row don't match. How do I do this?

One option would be to add a fourth column to spreadsheet in column D containing the following formula:
=IF(B1=C1, 1, 0)
Here is what your spreadsheet looks like now:
A B C D
0.99 p269 p269 1
0.99 p312 p312 1
0.64 p249 p249 1
0.64 p247 p247 1
0.09 p243 p284 0
In other words, if columns B and C agree, there is a 1 otherwise 0. Then, you can use the following COUNTIFS formula:
=COUNTIFS(A1:A5,">0.5",D1:D5,"=1")
Here we check the 0.5 threshhold on column A as you were already doing, but we also check that the B and C values are in agreement.

The other option is to use a pseudo-array formula
=SUMPRODUCT((A1:A5>F2)*(B1:B5=C1:C5))
to combine the two conditions. It doesn't have to be entered as an array formula, but may have performance issues if used on several thousand rows of data.

Related

excel formula to filter range based on criteria

I have a strange problem I've been trying to find a good solution to for the past few hours. I have a table in excel similar to the following:
|A B C D E F
-----+-----+-----+-----+-----+-----+-----
1 |2011 1 0 -5 4 2
2 |2011 2 1 1.2 2 3
3 |2011 3 1 2 4 -4
4 |2011 0 1 -3 3 -2
5 |2012 5 1 0 0 1
6 |2012 0 1 0.25 0 0
the data falls into different categories based on columns A-C, with columns D-F being dollar amounts.
What I'm trying to figure out is, is there a way to return the max absolute value of columns D-F for a subset of these rows using the values in columns A-C as filter values? Now, I know how to return the max absolute value of a range: =max(abs(START:END)), but what I don't know how to do is filter out some of the rows from the range based on their column A-C values.
Perhaps a specific example of what I'm looking for:
How would I get the range D-F where:
A=2011
B<>0
C=1
For the above set of conditions and data, the answer I'd like to have returned is 4, from E3.
I am not opposed to adding helper columns within reason, but there are many more sets of filter conditions, which was the undoing of a few other solutions I cobbled together; 16-32 helper columns would not be accepted by the group I'm trying to develop this for.
If your excel version supports the newer MAXIFS function, use that with the ABS function and MINIFS function.
=max(maxifs(d:f, a:a, 2011, b:b, "<>", c:c, 1), abs(minifs(d:f, a:a, 2011, b:b, "<>", c:c, 1)))
If not then AGGREGATE will provide the conditions.
=AGGREGATE(14, 6, ABS(D1:F6)/((A1:A6=2011)*(B1:B6<>0)*(C1:C6=1)), 1)

Excel, more efficient formula for multiple IF ANDS

I have a spreadsheet that I am making that looks as follows:
Index Diff Exc Sym Sec Result Criteria Met
3.42 -2.07 0.86 0.92 1.83 1.95
-0.38 -2.93 0.87 0.23 -2.01 0.09
-2.67 -1.84 0.87 -2.49 -3.48 1.32
-0.65 -0.98 0.46 0.98 -2.01 0.00
-0.73 -2.79 -1.07 -2.15 -1.44 -0.10
0.15 2.33 -0.46 -0.66 3.17 0.38 0.38
0.90 -3.68 -0.72 -1.01 -1.36 1.69
0.68 -1.12 -0.36 0.73 -1.34 -0.29
-1.19 -1.70 -0.56 -1.31 1.45 0.49
-0.45 -0.69 -0.56 -1.22 0.00 -0.49
2.94 8.38 2.21 6.25 4.96 1.74
-1.04 7.36 2.59 3.00 2.17 2.97
1.21 1.73 3.05 1.48 3.56 0.77
-1.10 1.86 0.60 1.18 1.07 -0.49
-0.89 -3.19 -1.78 -2.24 -4.26 -0.81
-1.17 -3.44 0.11 -1.22 3.66 0.36
0.52 0.92 -1.02 0.38 1.96 -1.40 -1.40
-0.90 3.01 -0.86 0.62 0.97 -0.50 -0.50
2.78 1.46 0.00 0.47 1.95 0.84
Max Min
Index 2.00 -2.00
Diff 10.00 0.00
Exc 0.00 -10.00
Sym 10.00 -10.00
Sec 20.00 0.00
Under the headings Index, Diff, Exc, Sym, Sec, Result is all data, In the criteria met column i have a formula that checks if the prior headings fall within the Max and Min limits of the smaller table underneath, and if they do it posts the result, if they dont all fall within the Max and Min boundaries it leaves it blank. I did that by using this formula:
=IF(AND(A3<$B$24,A3>$C$24,B3<$B$25,B3>$C$25,C3<$B$26,C3>$C$26,D3<$B$27,D3>$C$27,E3<$B$28,E3>$C$28),F3,"")
copied down the criteria met column. It works perfectly fine for what I want it to achieve but as this spreadsheet grows and I add more columns it seems like it will be incredibly inefficient and prone to alot of human error. Is there a way to achieve the same results but by using a more efficient formula?
a picture for reference as well:
Try this array formula:
=IF(SUM((A3:E3<=TRANSPOSE($B$24:$B$28))*(A3:E3>= TRANSPOSE($C$24:$C$28)))=COLUMNS(A3:E3),F3,"")
Being an Array Formula it must be confirmed with Ctrl-Shift-Enter when exiting Edit mode. When done correctly Excel will automatically put {} around the formula to denote an array formula.
One caveat, the Columns to be compared need to be in the same order as the min/max rows.
Also, as has been stated by nearly everyone if the Min Max were transposed to rows from column it would alleviate needing to use a CSE array formula. The following would work:
=IF(SUMPRODUCT((A5:E5>=$A$3:$E$3)*(A5:E5<=$A$2:$E$2))=COLUMNS(A5:E5),F5,"")
Try something like this:
=IF(PRODUCT(IF(ROW>TRANSPOSE(MIN),1,0),IF(ROW<TRANSPOSE(MAX),1,0))=1,RESULT,"")
In this example, A11:E11 is a row of data with RESULT in F11 and the MAX and MIN criteria are in $B$27:$B$31 and $C$27:$C$31, respectively.
=IF(PRODUCT(IF(A11:E11>TRANSPOSE($C$27:$C$31),1,0),IF(A11:E11<TRANSPOSE($B$27:$B$31),1,0))=1,F11,"")
Enter the expression as an array formula (CTRL-SHIFT-ENTER). Make sure to use a relative reference for each row of data and absolute references for the MAX and MIN criteria. Then copy/paste to evaluate other rows. Modifying this formula to accommodate additional columns of data can be done by extending the ranges.
If you are permitted to transpose the range that holds the MAX and MIN criteria to the same orientation as the data, the TRANSPOSE functions in this solution can be eliminated and the spreadsheet layout will be cleaner.
Hope that helps
How about:
=IF(AND(A3=MEDIAN(A3,B$24,C$24),B3=MEDIAN(B3,B$25,$C$25),C3=MEDIAN(C3,B$26,$C$26‌​),D3=MEDIAN(D3,B$27,$C$27),E3=MEDIAN(E3,B$28,$C$28)),F3,"")
I would also move the criteria table into a separate tab to avoid that you have to adjust the loacation of the min/max values in your formula every time you add new rows to your data table.
Often in Excel, in order to simplify your formulas, you need to make your layout a little more complex. Without writing any vba, my approach would be ...
1) I would transpose your min / max layout and have them align with the columns of data.
2) Insert another sheet to hold intermediate calculations.
Here's Sheet1 ...
and here's Sheet2 ...
In Sheet2, cell B5 contains a typical formula ...
=IF(AND(Sheet1!B5<Sheet1!B$2,Sheet1!B5>Sheet1!B$3),1,0)
In Sheet2, cell G5 (and down) contains ...
=PRODUCT(B5:F5)
In Sheet1, cell H5 (and down) contains ...
=IF(Sheet2!G5=0,"",Sheet2!G5*G5)
It could omit the logic and you could make the sheet settings to not display 0 values.
If you add columns (e.g. insert columns between Sheet1 column F and G):
- add Max and Min values for new columns on Sheet1
- insert the same columns on Sheet2
- drag the formula from column F on sheet2 to the new columns on Sheet2
- verify the Product formula in the "Result" column on Sheet2 contains the new columns on Sheet2.
This method helps identify exactly what caused you to fail to meet your criteria.

Excel - Include Row in Sum Based on Comparison to Following Row

Paging All Excel Wizards,
I am trying to see if there is a way to have a one-line SUMIF or something similar to sum up the following criteria in an Excel spreadsheet:
Sum the values of Column C if
If Column A = "Chizzle"
AND If Column B is >= Column B of the next row
Sample Data:
A B C
Type Level Value
__________________
Chizzle 1 23
Chizzle 2 10
Bobbles 3 1.5
Bobbles 3 2.6
Chizzle 2 5.5 <- Should Be counted
Cobbles 2 1
Chizzle 1 3.3 <- Should Be counted
I have tried using something like this:
=SUMIFS(C1:C1000,A1:A1000,"Chizzle", B1:B1000, ">=" & B2:B1001 )
Unfortunately the B2:B1001 part isn't working and it is selecting all values.
If there is a way to do this with a one line calculation, without having to add an additional column? That would be awesome but I'm not sure if it is possible.
Thanks!
Try this SUMPRODUCT():
=SUMPRODUCT(($A$2:$A$8="Chizzle")*($B$2:$B$8>=$B$3:$B$9)*($C$2:$C$8))

Best method to calculate provision from a table with provision levels?

I have a table with provision levels.
Sales Provision
0 5%
20 000 22%
100 000 30%
A salesman has 5% provision on the first 20 000, 22% on the next 80 000 and 30% on everything above that.
For example a salesman who sells for 230 000 will have provision
=20 000 * 0,05 + 80 000 * 0,22 + 130 000 * 0,30
How can I express this efficiently with a formula? The formula
Needs to be easy to copy to several rows (where a salesman is described by each row)
Needs to work even if I add more provision levels
Well I can say this works (hopefully) for requirement #2:
Needs to work even if I add more provision levels
But note that I am unsure about requirement #1:
Needs to be easy to copy to several rows (where a salesman is described by each row)
Anyway, with this data:
A B C D E
------------------------------------------
0 0.05 Value 230000
20000 0.22 Total Provision 57600
100000 0.3
I used this formula in E2:
=IFERROR(SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))+(E1-INDEX(A:A,MATCH(E1,A:A,1)))*INDEX(B:B,MATCH(E1,A:A,1)),E1*B1)
If we break this formula down:
The first basic step is to find the index at which the sale value resides. This is the first lower value compared to the sale value. In your example data this is straight forward because the index is the last in the provision list. However to accommodate sale values that fall within the list range we can use:
MATCH(E1,A:A,1)
where E1 is the sale value and A:A is the sale-provision list.
Using this we can incorporate an INDIRECT to get the desired range we need to work with. In this case A1 to A & Index:
INDIRECT("A1:A"&MATCH(E1,A:A,1))
But even within this range we need to figure out two distinct values:
The provision value index lower than our sale value (i.e. 20 000 * 0.05 + 80 000 * 0.22)
The rest of the provision sale value (i.e. 130 000 * 0.30)
So to get the first value we need to set up an array like this:
(20000 - 0) * 0.05 = 20000*.05 = 1000
(100000 - 20000) * 0.22 = 80000*.22 = 17600
SUM = 18600
That can be done by using
(A2:A3 - A1:A2)*(B1:B2)
But to put that in our INDIRECT formula, that would look like
INDIRECT("A2:A"&MATCH(E1,A:A,1)) <- A2:A3
INDIRECT("A1:A"&MATCH(E1,A:A,1)-1) <- A1:A2
INDIRECT("B1:B"&MATCH(E1,A:A,1)-1) <- B1:B2
(INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))
Just surround that with a SUMPRODUCT to get the total:
SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1,A:A,1))-INDIRECT("A1:A"&MATCH(E1,A:A,1)-1))*INDIRECT("B1:B"&MATCH(E1,A:A,1)-1))
Then the second value is just the total sale value subtracted by our index value and multiplied by the corresponding provision rate. So that would be:
(E1-A3)*B3
We actually don't need INDIRECT here, a couple INDEX - MATCH lookups will do:
E1 <- E1
INDEX(A:A,MATCH(E1,A:A,1)) <- A3
INDEX(B:B,MATCH(E1,A:A,1)) <- B3
(E1-INDEX(A:A,MATCH(E1,A:A,1)))*INDEX(B:B,MATCH(E1,A:A,1))
Then adding those to formulas together results in the derived formula I showed earlier.
The final addition however was to add an IFERROR wrapper because if the value is less than the first non-zero provision the INDEX-MATCH and INDIRECT will fail. So in the case of an error that means we just need to multiply the sale value by the first provision rate:
E1*B1
And of course if you add an additional provision row:
A B C D E
------------------------------------------
0 0.05 Value 230000
20000 0.22 Total Provision 63600
100000 0.30
200000 0.50
Or change the provision:
A B C D E
------------------------------------------
0 0.05 Value 22000
20000 0.22 Total Provision 1440
100000 0.30
The formula will index to the proper provision and calculate it properly.
Also,
Since I know I use commas and decimals in my locale and I realized you don't here is the formula for semi-colon list separator:
=IFERROR(SUMPRODUCT((INDIRECT("A2:A"&MATCH(E1;A:A;1))-INDIRECT("A1:A"&MATCH(E1;A:A;1)-1))*INDIRECT("B1:B"&MATCH(E1;A:A;1)-1))+(E1-INDEX(A:A;MATCH(E1;A:A;1)))*INDEX(B:B;MATCH(E1;A:A;1));E1*B1)

Want formula to return a number value or blank

I have two columns (A & B) of information. I'm trying to create a third (C) with the answer of B divided by A in the form of a percentage or if 100% a blank or dash (-). Below is an example.
I've tried several different formula combinations like =IF((B38/A38)<100,(B38/A38)," ") I can get the percentage answers okay but have not been able to get the wanted result of a blank or a dash.
**A** **B** **C**
1.99 0.99 49.7%
1.99 1.99
3.99 3.99 -
2.99 1.99 66.6%
Thank you for any help given.
100% displayed as an integer is 1, so you want =IF(B1/A1=1,"-",B1/A1)
You are not getting the desired result for the blank because the statement is always true. replace 100 by 100%-
=IF((B38/A38)<100%,(B38/A38),"")

Resources