excel formula to filter range based on criteria - excel

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)

Related

Excel using SUMIF to calculate totals of multiple columns

I'm trying to use Excle's SUMIF to calculate totals of Col1 to Col5 for dates that are similar.
My formula is as follows =SUMIF($A2:$A7,A10,$B2:$F7), but this only gives me the total of a single column.
How can I get the Totals of all the columns based on the date like I've shown in my results.
Date Col 1 Col 2 Col 3 Col 4 Col 5
1/5/2017 1 2 2
1/5/2017 5 3 1
1/5/2017 9 5 5
2/5/2017 10 5 3
2/5/2017 20 10 3
2/5/2017 6 8 1 5
Desired Results
1/5/2017 15 7 7 3 1
2/5/2017 30 11 11 11 8
use below formula in cell B11
=SUMIF($A$2:$A$7,$A11,B$2:B$7)
Per the example you provided, One solution is to use SUMPRODUCT
Multiplies corresponding components in the given arrays, and returns the sum of those products
Microsoft Docs give a thorough example, but per SO etiquette, here is an example in case of link-rot: [FYI, I used absolute reference for easier filling across, arbitrary how you get it done though]
Forumlas shown:
Formula is kind of hard to see without clicking on image:
=SUMPRODUCT(($B$3:$B$8=$B$11)*C3:C8)
This basically breaks down like this, it searches the B:B column for a match, and it will naturally return a true or false for the match, or 0/1 counterparts, and multiplys that by the number found in the column to the right (C3:C8), so it will either be 1 * # = # or 0 * # = 0

Excel 2013 complex countif formula

I have a source sheet set up like this:
Days Open Month
10 1
4 1
6 1
2 1
4 2
2 2
-1 2
4 3
6 3
7 4
3 4
etc
I'm trying to set up a formula to count rows based on the following criteria:
cells in Days Open column <=5 and <>-1 where the month is either 2, 3, or 4 (the worksheet will eventually have month numbers up to 12, and I need to group results quarterly). The total must then be divided by the total of ALL rows in which 2, 3, or 4 appears in the Month column.
I can't seem to get the first part of the COUNTIFS to work with both criteria... this is what I have so far that I'm trying to make work:
=COUNTIFS('Cumulative Complaints'!K:K,"<=5",'Cumulative Complaints'!K:K,"<>-1")/(COUNTIF('Cumulative Complaints'!L:L,"2")+COUNTIF('Cumulative Complaints'!L:L,"3")+COUNTIF('Cumulative Complaints'!L:L,"4"))
I've been looking around here and other excel forums and think maybe SUMPRODUCT is the way to go? I haven't been able to get that to work though, given the criteria needed on the Days Open column (<=5 and <>-1).
Try this SUMPRODUCT() FORMULA:
=SUMPRODUCT(('Cumulative Complaints'!K:K<=5)*('Cumulative Complaints'!K:K<>-1)*('Cumulative Complaints'!L:L>=2)*('Cumulative Complaints'!L:L<=4))/SUMPRODUCT(('Cumulative Complaints'!L:L>=2)*('Cumulative Complaints'!L:L<=4))
When using the SUMPRODUCT the condition AND is replaced with the *. It requires all four conditions to be True to return a 1; 1*1*1*1 = 1 if any are false they return 0 so 1*1*0*1 = 0. So as it iterates through the rows it returns a 1 or a 0 to the be added to the sum.
Wrapping a COUNTIF or COUNTIFS function in a SUM function allows you to use an array of constants as OR citeria.
=SUM(COUNTIFS('Cumulative Complaints'!K:K, "<>"&-1,'Cumulative Complaints'!K:K, "<="&5,'Cumulative Complaints'!L:L, {2,3,4}))/SUM(COUNTIF('Cumulative Complaints'!L:L, {2,3,4}))
This is not an array formula and does not require CSE.
My answer would be to take a different approach.
Excel has a very powerful feature called Pivot Tables, and I think it might be a good fit for your problem and other similar problems you may face.
First, I would add a couple columns to your table, like so:
Days Open Month Quarter RecentlyOpened
10 1 1 FALSE
4 1 1 TRUE
6 1 1 FALSE
2 1 1 TRUE
4 2 1 TRUE
2 2 1 TRUE
-1 2 1 FALSE
4 3 1 TRUE
6 3 1 FALSE
7 4 2 FALSE
3 4 2 TRUE
The formula for Quarter is: =CEILING(B2/3,1)
The formula for RecentlyOpened is: =AND(A2<>-1,A2<=5)
Second, select the table, and do Insert > Pivot Table.
Third, drag from the fields to the boxes, like so:
Drag Quarter to the ROWS box
Drag RecentlyOpened to the FILTERS box
Drag Month to the VALUES box
Fourth, click Sum of Month, and select Value Field Settings to change Sum to Count.
Fifth, set the RecentlyOpened filter to TRUE.
The result is this:
Pivot Tables often provide a solution that is more flexible and easier to read and understand versus complex formulas.

Index and Match across a wide range of values

I have a bunch of data in a few columns, but basically:
Bunch #1 (column A,B):
CHR POS
1 126234
3 5555555
3 9999999
9 3700000
Bunch #2 (column E,F,G):
CHR POS INDEX
1 1129410 1
2 4500000 2
3 5555155 3
3 9997999 4
7 3700000 5
I wish to add a column in Bunch #1 such that if the CHR column of both bunches are the same, AND the POS column of #2 is within +/-500 of POS in #1, then copy over the index of Bunch #2.
Like so (Column A,B,C):
CHR POS NEW_COLUMN
1 126234 #N/A
3 5555555 3
3 9999999 #N/A
9 3700000 #N/A
I got as far as getting exact matches for both columns in C
{=INDEX(E:G,match(1,(E:E=A1)*(F:F=B1),0),3)}`
Some help in getting the range condition into the match would be very much appreciated.
The newer AGGREGATE¹ function makes quick work of multiple conditions. In C2 as,
=IFERROR(INDEX(G$1:G$9, AGGREGATE(15, 6, ROW($1:$9)/((E$1:E$9=A2)*(F$1:F$9<=B2+500)*(F$1:F$9>=B2-500)), 1)), "no match")
Fill down as necessary.
      
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

Add values for each cell values those are followed up and add 0 for missing date values in excel

I have two columns
Quantity Date
2 02/01/2014
3 04/01/2014
4 07/01/2014
5 07/01/2014
1 08/01/2014
3 08/01/2014
I want to add the quantity values for each date and put 0 for dates those are missing. So end result would look like below
Quantity Date
0 01/01/2014
2 02/01/2014
0 03/01/2014
3 04/01/2014
0 05/01/2014
0 06/01/2014
9 07/01/2014
4 08/01/2014
0 09/01/2014
. ...
. ...
. ...
Can't think of a way, can someone help please
I don't have Excel in front of me, but I'll take a stab at it.
Leave your first dataset in Sheet1, but reverse the columns.
Then type
Date
01/01/2014
02/01/2014
03/01/2014
....
...into Column A of Sheet2 and drag the cells down to expand the series as far as it needs to go.
Then do a =vlookup(A1, Sheet1!A$1$:B$99999$, 2, FALSE) in column B of sheet two.
You'll get errors, where you don't have dates in Sheet1, so you can fill those in by modifying the above equation to: =IFERROR(vlookup(A1, Sheet1!A$1$:B$99999$, 2, FALSE), 0)
(I think).

Spreadsheets: how do I SUM values in a column, only if the text column has a 1?

Let's say I have this data
4 1
4 0
4 1
3 0
5 1
How do I write a function (using SUM or something like that) to add all the values on the left, if the values on the right are 1, or true
The total should be 13
Assuming columns A and B are used...
Check just for 1:
=SUMIF(B1:B5,"=1",A1:A5)
If you want to check for TRUE also:
=SUMIF(B1:B5,"=1",A1:A5) + SUMIF(B1:B5,"=TRUE",A1:A5)
sort by column b, then auto-sum the values you want in column a. cheap & lazy solution.

Resources