Find value using multiple criteria - excel

I've got a table with columns, each containing customer contact information. I've also got a formula that finds a phone number using multiple criteria: customer ID, type (mobile, home etc), and primary Y/N. The problem is this information can occur several times but with a different date, in which case the newest occurrence needs to be selected. The current CSE formula is:
=INDEX($C$6:$BZ$18;10;MATCH(<client_ID>;IF(($C$8:$BZ$8=<client_ID>)*($C$17:$BZ$17="home")*($C$18:$BZ$18="Y");$C$8:$BZ$8);0))
where
$C$6:$BZ$18 contains all data
$C$8:$BZ$8 contains all client IDs
$C$17:$BZ$17 contains the types of phone numbers
$C$18:$BZ$18 contains whether this number is the primary number of that type
$C$8:$BZ$8 contains the date a number was entered
The data looks like this:
B C D
---------------------------------------------------------------------
8 CLIENTID |Client1 |Client1 |
9 other | | |
10 other | | |
11 other | | |
12 other | | |
13 other | | |
14 other | | |
15 PHONE NUMBER |9876543210 |1234567890 |
16 DATE |2015-04-15 |2015-04-16 |
17 TYPE |Home |Home |
18 Primary |Y |Y |
The above formula selects phone number 9876543210 but it needs to select 1234567890 because that is the latest entry.
Any ideas on how to proceed from here?

The underlying value of dates are numbers so we can look for the furthest date to the right in a row by searching for an impossibly high number with the MATCH function without looking for an exact match.
      
The array formula in F6 is,
=INDEX($B$8:$BZ$18, MATCH(F$5, $B$8:$B$18, 0), MATCH(1E+99, IF($B$8:$BZ$8=$C6, IF($B$17:$BZ$17=$D6, IF($B$18:$BZ$18=$E6, $B$16:$BZ$16)))))
Array formulas need to be finalized with Ctrl+Shift+Enter↵.
If your dates are in ascending order (left-to-right) then an exact match will have to be sought. A three criteria pseudo-MAXIF formula can return that into the original formula modified to look for an exact match. If the maximum date is duplicated, the first one is returned.
=INDEX($C$8:$BZ$18, MATCH(F$5, $B$8:$B$18, 0), MATCH(MAX(INDEX($C$16:$BZ$16*($C$8:$BZ$8=$C6)*($C$17:$BZ$17=$D6)*($C$18:$BZ$18=$E6), , )), IF($C$8:$BZ$8=$C6, IF($C$17:$BZ$17=$D6, IF($C$18:$BZ$18=$E6, $C$16:$BZ$16))), 0))
In order to provide some maths without errors, I've shifted the calculation ranges to C:BZ. Array formulas still need to be finalized with Ctrl+Shift+Enter↵.
By appropriately locking either the row, column or both of the cell addresses, we can use the column header to identify a different category from column B as I have done with DATA LINE. The formula can be simply filled right.

Related

Finding % based on multiple cells and using MATCH formula

Trying to come up with a formula for a spreadsheet I am working on, but hit a road block.
I need to use an INDEX and MATCH formula to ensure that the cell is going to lookup a sheet full of data and find all matches based on an ID number. I then need to work out the % value of how often that column was populated with data for that ID number.
Essentially as an example:
The data table would look like:
ID | Notes Added
1 | Yes
7 | Yes
12 | Yes
6 | Yes
10 |
12 |
And the result would be:
ID | Populated %
12 | 50 %
As you can see, the values that it should return would be 50%, as there are 2 entries that are listed for the ID of 12 (this is where the MATCH and INDEX would come in), however in the Notes Added, only 1 of the entries has a value.
The data table that it draws from will either have a value, or have no value, calculating the % would be based on if there is/isn't a value.
You'll want to use COUNTIFS Function. It would look something like this:
=COUNTIFS(B4:B9,C16,C4:C9,"Yes") / COUNTIF(B4:B9,C16)
=COUNTIFS(<ID Values Range>,<Id Value>,<notes added range>,"Yes") / COUNTIF(<ID Values Range>,<Id Value>)
Then just set the cell formatting to %.

Structured Reference in an Index/Match Calculated Column Formula for Header Cell Range in a Table

I have this formula in a calculated column that is working great:
=IFERROR(INDEX(Allocation_of_Funds[[#Headers],[End.Nursing]:[Unassigned14]],MATCH(TRUE,INDEX(Allocation_of_Funds[#[End.Nursing]:[Unassigned14]]>0,0),0)),"")
But this formula is giving me trouble and represents what I want in the next calculated column, (based on the value in the previous column above) but it returns a #REF! error:
=INDEX(INDIRECT("Allocation_of_Funds[[#Headers]"&"["&[#[SOURCE 1]]&"]"):[#Unassigned14],MATCH(TRUE,INDIRECT("Allocation_of_Funds[[#Headers]"&"["&[#[SOURCE 1]]&"]"):[#Unassigned14]>0,0),0)
The details of the tables setup is as follows, in case it's helpful:
I have a table with a range of columns and each column represents a different type of account. For each row, any combination of these columns could contain values or blanks, so I've got another set of columns that I want to identify the table column headers for the non-blank columns for each record.
SOURCE1 | SOURCE2 | SOURCE3 | ACCT1 | ACCT2 | ACCT3 | ACCT4 | ACCT5
ACCT1 | ACCT2 | ACCT4 | 500 | 300 | | 100 |
ACCT2 | ACCT3 | | | 200 | 100 | |
ACCT3 | | | | | 500 | |
| | | | | | |
ACCT3 | ACCT4 | ACCT5 | | | 200 | 300 | 50
ACCT1 | ACCT3 | ACCT4 | 123 | | 332 | 100 |
So I need the SOURCE2 column to use the value in the SOURCE1 column to identify the start of the range where I am looking for the next cell with a value, whereby the column header above that value will be returned for the SOURCE2 row value. The same formula will apply to the SOURCE3 column, using the value of the SOURCE2 column to identify the start of the next range.
Thank in advance for picking your brain!
-Lindsay
I used the following formula to pull the headers and place them under the source numbers:
=IFERROR(INDEX($D$1:$H$1,AGGREGATE(15,6,COLUMN($D2:$H2)/ISNUMBER($D2:$H2)-COLUMN($D$1)+1,RIGHT(A$1,1)*1)),"")
I assumed your table's top left corner was in A1 with 1 being the header row and A-C being your source columns and D to H being account columns. The above formula can be placed in cell A2 and copied to the right and down as need be.
You seem to have a grasp of the IFERROR and INDEX function so I will explain the AGGREGATE function:
=AGGREGATE(15,6,COLUMN($D2:$H2)/ISNUMBER($D2:$H2)-COLUMN($D$1)+1,RIGHT(A$1,1)*1)
The AGGREGATE function is a mixture of a bunch of different functions rolled into with the ability to ignore some calculations. Another added feature is that some of the built in functions perform array calculations without the need for arrays.
In this particular case I chose aggregate function 15 which is the same as the SMALL function. I have also told aggregate to ignore calculations which generate errors by using the "6". For the array calculation I have asked it to divide the column number it is working with by the True or False result of that column being a number:
COLUMN($D2:$H2)/ISNUMBER($D2:$H2)-COLUMN($D$1)+1
True in excel math is the same as 1 and False is the same as 0. Anytime the cell is not a number it will try to divide by zero, generate an error, and be ignored by Aggregate function. This basically generates a list of column numbers that meet the criteria of having a number in their column. The subtraction of the D1 followed by a +1 is to convert the column number that is determined, to a relative column under your accounts headers.
The next part of the aggregate function is telling the SMALL operation which number in sorted order needs to be returned. I used the last character in your source header to determine which column number to return. For SOURCE1 the last character is 1 so I want the smallest column number returned. For SOURCE2, the second smallest number is returned. The *1 at the end converts the character to a number instead of 1 as text.
RIGHT(A$1,1)*1
Ergo, if you want to use up to 9 sources you can. You can do more sources as well but you would need to revise this formula or come up with a different way of providing which number of the small list you want returned. And you can expand the D2:H2 reference to be all your accounts, and adjust the D1:H1 reference to cover all your account headers.
Proof of Concept

Counting the number of older siblings in an Excel spreadsheet

I have a longitudinal spreadsheet of adolescent growth.
ID | CollectionDate | DOB | MOTHER ID | Sex
1 | 1Aug03 | 3Apr90 | 12 | 1
1 | 4Sept04 | 3Apr90 | 12 | 1
1 | 1Sept05 | 3Apr90 | 12 | 1
2 | 1Aug03 | 21Dec91 | 12 | 0
2 | 4Sept04 | 21Dec91 | 12 | 0
2 | 1Sept05 | 21Dec91 | 12 | 0
3 | 1Aug03 | 30Jan89 | 23 | 0
3 | 4Sept04 | 30Jan89 | 23 | 0
This is a sample of how my data is formatted and some of the variables that I have. As you can see, since it is longitudinal, each individual has multiple measurements. In the actual database there are over 10 measurements per individual and over 250 individuals.
What I am wanting to do is input a value signifying the number of older brothers and older sisters each individual has. That is why I have included the Mother ID (because it represents genetic relatedness) and sex. These new variable columns would just say how many older siblings of each sex each individual has. Is there a formula that I could use to do this quickly?
=COUNTIFS($B:$B,"<>"&$B2,$H:$H,$H2,$AI:$AI,$AI2,$J:$J,"<"&$J2)
Create a column named Distinct with this formula
=1/COUNTIF([ID],[#ID])
Then you can find all the older 0-sexed siblings like this
=SUMPRODUCT(([DOB]>[#DOB])*([MOTHERID]=[#MOTHERID])*([Sex]=0)*([Distinct]))
Note that I made the data a Table and used table notation. If you're not familiar [COLUMNNAME] refers to the whole column and [#COLUMNNAME] refers to the value in that column on the current row. It's similar to saying $A:$A and A2 if you're dealing with column A.
The first formula gives you a value to count that will always result in 1 for a particular ID. So ID=1 has three lines and Distinct will result in .33333 for each line. When you add up the three lines you get 1. This is similar to a SELECT DISTINCT in Sql parlance.
The SUMPRODUCT formula sums [Distinct] for every row where the DOB is greater than the current DOB, the Mother is the same as the current Mother, and the Sex is zero.
I have a possible solution. It involves adding two columns -- One for "# older siblings" and one for "unique?". So here are all the headings I have currently:
A -- ID
B -- CollectionDate
C -- DOB
D -- MOTHER ID
E -- Sex
F -- # older siblings
G -- unique?
In G2, I added the following formula:
=IF(A2=A1,0,1)
And dragged down. As long as the data is sorted by ID, this will only display "1" once for each unique person.
In F2, I added the following formula:
=COUNTIFS(G:G,"=1",D:D,"="&D2,C:C,"<"&C2)
And dragged down. It seemed to work correctly for the sample data you provided.
The stipulations are:
You would need the two columns.
The data would need to be sorted by ID
I hope this helps.
You need a formula like this (for example, for row 2):
=COUNTIFS($A:$A,"<>"&$A2,$E:$E,$E2,$D:$D,$D2,$C:$C,"<"&$C2)
Assuming E:E is column for sex, D:D is column for mother ID and C:C is column for DOB.
Write this formula in H2 cell for example and drag it down.

Count number of rows where multiple criteria are met

I'm trying to generate a table that shows a count of how many items are in any given status on any given day. My result table has a set of Dates down column A and column headers are various statuses. A sample of my data table with headers looks like this:
Product | Notice | Assigned | Complete | In Office | In Accounting
1 | 5/5/13 | 5/7/13 | 5/9/13 | 5/10/13 | 5/11/13
2 | 5/5/13 | 5/6/13 | 5/8/13 | 5/9/13 | 5/10/13
3 | 5/6/13 | 5/9/13 | 5/10/13 | 5/10/13 | 5/10/13
4 | 5/4/13 | 5/5/13 | 5/7/13 | 5/8/13 | 5/9/13
5 | 5/7/13 | 5/8/13 | 5/10/13 | 5/11/13 | 5/11/13
If my output table were to contain a set of dates in the first column with the statuses as headers, I need a count of how many rows were at the given status and had not yet transitioned to the next status so that in the Notice column, I'd have a count of rows where the Notice Date was <= X AND where the Assigned, Complete, In Office, In Accounting are all greater than X.
I've used a Sum(if(frequency(if statement to get me REALLY close but I feel like I need to have an AND statement within the second IF like this =SUM(IF(FREQUENCY(IF(AND
Here's what I have that won't work:
=SUM(IF(FREQUENCY(IF(AND(Table1[Assigned]<=A279,Table1[[Complete]:[In Accounting]]<=A279),ROW(Table1[[Complete]:[In Accounting]])),ROW(Table1[[Complete]:[In Accounting]]))>0,1))
If I take the "AND" portion out, this works fine except I need it to ONLY count rows where the given status actually has a date so if an "Assigned" date is empty, I don't want that row to be counted for the Assigned column.
Here's an example of what I'd expect to see in the results. I've listed the count in the each column as well as the corresponding product numbers in parenthesis. The corresponding product numbers are for reference only and won't actually be in the result table.
Date | Notice | Assigned | Complete
5/6 | 2 (1,3) | 2 (2,4) | 0
5/7 | 2 (3,5) | 2 (1,2) | 1 (4)
5/8 | 1 (3) | 2 (1,5) | 1 (2)
OK, assuming you have the original data in A1:F6 then with 2nd table headers in B9:D9 and row labels in A10:A12 then you can use this "array formula" in B10
=SUM((B$2:B$6<=$A10)*(MMULT((C$2:$F$6>$A10)+(C$2:$F$6=""),TRANSPOSE(COLUMN(C$2:$F$6)^0))=COLUMNS(C$2:$F$6)))
confirmed with CTRL+SHIFT+ENTER and copied down and across (see screenshot below)
As you can see the results are as per your requirement. If you replace dates with blanks it will still work
MMULTis a way to get a single value from each row even when you are looking at multiple columns.
I used cell references because I think that's easier, especially when copying the formula across and having a reducing range.......but you can use structured references if you want
Have you tried using COUNTIFS to count based on multiple criteria. It is fairly well documented here: http://office.microsoft.com/en-us/excel-help/countifs-function-HA010047494.aspx (2007+ only)
Basically, you use it like
=COUNTIFS(first_range_to_check, value_you_want_in_first_range, ...)
where the ... represents as many pairs as you want (up to 127 total pairs), note the conditions are AND connection so if you have two pairs, the first pair AND the second pair must return true for that row to count.

MS Excel - finding the first row after a certain date

Say I have a spreadsheet with the following, and for convenience say all of this starts from cell A1.
---------------------------------------
| Date | Item | Account |
---------------------------------------
| 01/09/2011 | Testing 1 | USD |
| 03/09/2011 | Testing 2 | USD |
| 11/09/2011 | Testing 3 | USD |
| 20/10/2011 | Testing 4 | JD |
| 22/10/2011 | Testing 5 | JD |
| 25/10/2011 | Testing 6 | USD |
| 03/11/2011 | Testing 7 | USD |
| 05/11/2011 | Testing 8 | JD |
---------------------------------------
Now, I want to run a report for a month, starting on 1/10/2011 and ending on 31/10/2011. I need to find the first row on or after the starting date, and then get every subsequent row until the end date. If I can figure out how to get the row reference for the first and end dates, then I can figure out the rows in between (obviously!).
I have only been able do these sorts of matches on exact matches ie. no idea how to do 'greater/less than' matches.
How would I go about matching on both the date and the account columns?
Needless to say, this needs to be in a formula.
=match(date(2011,10,1),a2:a9,1)+1
=match(date(2011,10,31),a2:a9,1)
First formula shows row for the first record for October, second formula for the last day. Data must be sorted in ascending order.
Use the following Array Formula for finding the Row containing the earliest date, which is equal to or greater than the date mentioned in cell C1 (in your case this is 1 October).
=MATCH(MIN(IF($A$1:$A$30>=C1,1,9999)*$A$1:$A$30),$A$1:$A$30,0)
Date list is in cells A1 to A30. Change the references as required.
Data need not be sorted in ascending or descending order.
Use the following Array Formula for finding the Row containing the latest date which is equal to or less than the date mentioned in cell D1 (in your case this is 31 October). Data need not be sorted in ascending or descending order.
=MATCH(MAX(IF($A$1:$A$30<=D1,1,0)*$A$1:$A$30),$A$1:$A$30,0)
If you want the earliest and latest dates, use the following Array Formulas.
=MIN(IF($A$1:$A$30>=C1,1,9999)*$A$1:$A$30)
=MAX(IF($A$1:$A$30<=D1,1,0)*$A$1:$A$30)
All the formulas used above are Array Formulas. To enter an array formula, use Control+Shift+Enter instead of Enter.
Vijaykumar Shetye, Goa, India
I would recommend using a pivot table for this. Look at the second link on in the "Excel Templates - Pivot Table" section on this page on the Contextures site.

Resources