Count X records matching certain conditions and only where there is a corresponding Y record - excel

I am looking for some help with a formula. On my 'data' sheet, I have data in the format below:
A B C D E F G H I J
1 UID RecordType HCode AdmittedDate Forename Surname DOB Sex STDate RDate
2 87962 STAsses STIV1 01/01/2012 Mark Jones 13/07/1978 Male 09/12/2012
3 89658 Transfer GLSI2 01/01/2012 Alison Aitken 20/12/1956 Female 08/07/2013
4 84563 Discharge JHOP1 01/01/2012 David Beckham 09/08/1987 Male 08/07/2013
5 89654 STAsses STGE1 01/01/2012 Andrew Macbeth 27/09/1976 Male 08/07/2012
6 89867 Transfer KIND1 01/01/2012 George Deas 08/05/1989 Male 08/07/2013
7 87962 Transfer STIV1 01/01/2012 Mark Jones 13/07/1978 Male 04/03/2013
8 89654 Transfer STGE1 01/01/2012 Andrew Macbeth 27/09/1976 Male 12/08/2012
On my 'report' sheet, I have the following table set up:
B C D E F
4 HospCode RecordType Jul-12 Aug-12 Sep-12
5 STGE1 Assessments
6 Transfers
7 Discharges
8
What I need is a formula in cell D6 of the 'report' sheet, which counts all 'Transfer' records from the 'data' sheet, occurring in the month specified in D4 and with an 'HCode' matching that in B5 of the 'report' sheet. The tricky part is that I need this formula only to count records which have a corresponding 'STAssess' record.
Might be pushing the limits of Excel here, but anything is possible!
Thanks in advance.

You can simply use
=COUNTIFS(Sheet1!B1:B8, "Transfer", Sheet1!C1:C8, Sheet2!B5)
This is an example with 2 criteria, you can add a lot many more for multiple IFS and COUNTIFS will count those.
In case of finding multiple criteria across rows, you are better off making a Pivot Table out of this data range and then doing multiple selections thereof.
If you would like to accomplish this via formula, there is a two-step process.
THe formula described above needs to be placed next to each Person's name in Sheet1 as an additional column. And then run another COUNTIFS on this column and Column B counting that there is >1 Count for the person existing... and counting if the STAssess criterion is fulfilled or not.

Related

Updating spreadsheet after altering the original one

I have the following data in spreadsheet A.
name trait1 trait2 nice
0 Adam 29 81 0
1 Barry 17 75 1
2 Chris 62 0 1
I wish to create a spreadsheet B that will be a filtered copy of this data. Namely, let's assume for a moment that I want to filter nice = 1 and am interested only in column name. The copy in spreadsheet B would be as shown below. In spreadsheet B I wish to be adding some extra columns, e.g. education.
name nice education
1 Barry 1 primary
2 Chris 1 university
What I want to achieve is a spreadsheet B that will get updated if anything changes in spreadsheet A. So for example, if I were to change the name Barry to Ben. The spreadsheet B would become the following.
name nice education
1 Ben 1 primary
2 Chris 1 university
Similarly (and what I find to be the hardest), if a row is added in spreadsheet A, e.g.
name trait1 trait2 nice
0 Adam 29 81 0
1 Barry 17 75 1
2 Matt 69 11 1
3 Chris 62 0 1
The updated spreadsheet B would be as follows:
name nice education
1 Barry 1 primary
2 Matt 1
3 Chris 1 university
So I want the education column to remain the same.
My approach of using a combination of =IF() and =VLOOKUP() functions ultimately did not work. Guess I am really curious about how to connect rows of education to names. So that when a row is added in spreadsheet A, then spreadsheet B gets updated but the education field connected to the new row is empty and will be filled by hand later on.
Since you are looking for a finished product to be in Google Sheets, I'd advise to use QUERY():
Formula in I1:
=QUERY(INDEX({A:D,VLOOKUP(A:A,F:G,2,0)}),"Select Col1,Col4,Col5 where Col4=1")
Note: I made the assumption you pull the education in through a VLOOKUP() (since you mentioned that in the body of the question).

Excel: Challenging formula sought for counting records

I am looking for some help with a formula. On my 'data' sheet, I have data in the format below:
A B C D E F G H I J
1 UID RecordType HCode AdmittedDate Forename Surname DOB Sex STDate RDate
2 87962 STAsses STIV1 01/01/2012 Mark Jones 13/07/1978 Male 09/12/2012
3 89658 Transfer GLSI2 01/01/2012 Alison Aitken 20/12/1956 Female 08/07/2013
4 84563 Discharge JHOP1 01/01/2012 David Beckham 09/08/1987 Male 08/07/2013
5 89654 STAsses STGE1 01/01/2012 Andrew Macbeth 27/09/1976 Male 08/07/2012
6 89867 Transfer KIND1 01/01/2012 George Deas 08/05/1989 Male 08/07/2013
7 87962 Transfer STIV1 01/01/2012 Mark Jones 13/07/1978 Male 04/03/2013
8 89654 Transfer STGE1 01/01/2012 Andrew Macbeth 27/09/1976 Male 12/08/2012
On my 'report' sheet, I have the following table set up:
B C D E F
4 HospCode RecordType Jul-12 Aug-12 Sep-12
5 STGE1 Assessments
6 Transfers
7 Discharges
8
I would like to do 2 things.
In D5, E5, F5, a formula is needed to return the number of 'STAssess' records for HCode 'STGE1' from the data sheet, which were completed in the month shown in D4 of the 'report' sheet (Jul-12). The dates for these records are in column I of the data sheet - 'STDate'.
I've tried using SUMPRODUCT which works to an extent, but I'm having difficulty bringing back records only completed in July. I need the formula to be dynamic in that it only brings back results for the month entered in D4 (so a date range built into the formula isn't doing the job).
In D5, E5, F5, I need to bring back the number of records from the 'data' sheet, which have 'Transfer' in column B (RecordType), 'STGE1' in column C (HCode) and a date in column J (RDate) which falls in the month specified on D4 of the 'report' sheet (Jul-12).
Anyone got any ideas? The data sheet is actually going to be an external .csv file which can't be manipulated. I don't mind using other hidden sheets to do any sorting that needs to be done, provided that this can be setup so that when the data is brought in, no extra work has to be done.
Thanks!
For both of your questions you can use COUNTIFS. It is easier to understand (for me) and compatible with Excel 2007 and newer.
First question:
=COUNTIFS(DATA!B:B,"STAsses",DATA!C:C,$B5,DATA!I:I,">="&D$4,DATA!I:I,"<"&DATE(YEAR(D4),MONTH(D4)+1,1))
Second question:
=COUNTIFS(DATA!B:B,"Transfer",DATA!C:C,$B5,DATA!J:J,">="&D$4,DATA!J:J,"<"&DATE(YEAR(D4),MONTH(D4)+1,1))
And these formulas can be dragged across your needed range.
Here is an example formula that you could use for the D5 cell, does that point you in the right direction?:
{=SUM(IF($B$2:$B$8=$B14,IF($C$2:$C$8=$A14,IF($D$2:$D$8=C$13,1,0),0),0))}
This is an array function so you must enter it without the {} at each end and use Ctrl + Shift + Enter to enter the formula.
If your summary table looks like
HospCode RecordType 12-Jul 12-Aug 12-Sep
STGE1 STAsses 1 0 0
STGE1 Transfer 0 1 0
STGE1 Discharges 0 0 0
And your data is in a table called Table1, then in D5
=SUMPRODUCT((Table1[HCode]=$B5)*(Table1[RecordType]=$C5)*(MONTH(Table1[STDate])=MONTH(D$4)))
I'm not sure what you mean by 'bring back', but assume you mean that you want to show it when RecordType = column C and when the RecordType = "Transfer" and the RDate is in the right month. Then
=SUMPRODUCT((Table1[HCode]=$B5)*(Table1[RecordType]=$C5)*(MONTH(Table1[STDate])=MONTH(D$4)))+SUMPRODUCT((Table1[HCode]=$B5)*(Table1[RecordType]="Transfer")*(MONTH(Table1[RDate])=MONTH(D$4)))

Excel to find value from one sheet & show to another sheet

I have a sheet1 where column A= employees name & column B=Status (present, absent, etc), I prepare Daily attendance in each sheets, so I have 31 sheets in a month. Now I have a new sheet November. in this sheet column A is employees name and column B, C, D, etc for each days status. show me status of each employes in each days B, C, etc
You would use the VLOOKUP statement to fetch the status from the other sheets.
This is in the format:
vlookup([cell which has the value you want to lookup], [range of cells which contain the table], [column you want to return from that table]). Hopefully this is explained in the example below:
For ease of explanation, imagine your sheets are named Nov1, Nov2... Nov29, Nov30 and NOVEMBER.
Nov1:
A B
1 Employee Name Status
2 Albert Present
3 Brian Absent
4 Catherine Present
5 David Present
6 Edward Present
Nov2:
A B
1 Employee Name Status
2 Albert Absent
3 Brian Absent
4 Catherine Present
5 David Absent
6 Edward Absent
Then, in your sheet NOVEMBER, which is the month summary, use the formulae:
A B C
1 Employee Name Nov 1st Nov 2nd
2 Albert =VLOOKUP($A2,Nov1!$A$2:$B$6,2) =VLOOKUP($A2,Nov2!$A$2:$B$6,2)
3 Brian =VLOOKUP($A3,Nov1!$A$2:$B$6,2) =VLOOKUP($A3,Nov2!$A$2:$B$6,2)
4 Catherine =VLOOKUP($A4,Nov1!$A$2:$B$6,2) =VLOOKUP($A4,Nov2!$A$2:$B$6,2)
5 David =VLOOKUP($A5,Nov1!$A$2:$B$6,2) =VLOOKUP($A5,Nov2!$A$2:$B$6,2)
6 Edward =VLOOKUP($A6,Nov1!$A$2:$B$6,2) =VLOOKUP($A6,Nov2!$A$2:$B$6,2)
Using the $ symbol will mean you can copy down the column and the formulae will update automatically. Ensure that the list of employees in your separate daily sheets are in alphabetical order.
So this should result in something like this:
A B C
1 Employee Name Nov 1st Nov 2nd
2 Albert Present Absent
3 Brian Absent Absent
4 Catherine Present Present
5 David Present Absent
6 Edward Present Absent

Excel - Counting unique records in a group

I'm having difficulty counting records in a file that have a unique ID and listing the number of rows associated with that specific ID.
For this file, the unique ID represents a specific family (column A). Each member of the family is in a different row with the same ID. I would like to count the number of family members(rows) in each unique family. I can have a few thousand rows so automating this would be wonderful. Thanks for any help!!
You can do this now automatically with Excel 2013.
If you have that version, then select your data to create a pivot table, and when you create your table, make sure the option 'Add this data to the Data Model' tickbox is check (see below).
Then, when your pivot table opens, create your rows, columns and values normally. Then click the field you want to calculate the distinct count of and edit the Field Value Settings:
Finally, scroll down to the very last option and choose 'Distinct Count.'
This should update your pivot table values to show the data you're looking for.
So if I'm understanding you correctly, you have something like
A B C
Fam. ID LastName FirstName
1 Smith John
1 Smith Mary
1 Smith Johnnie Jr
2 Roe Rick
3 Doe Jane
3 Doe Sam
and you want a new column (say, D), with a count of members per family:
A B C D
Fam. ID LastName FirstName Fam. Cnt
1 Smith John 3
1 Smith Mary 3
1 Smith Johnnie Jr 3
2 Roe Rick 1
3 Doe Jane 2
3 Doe Sam 2
This will do it -- insert at D2 and drag down:
=COUNTIF(A:A,A2)

multiple conditions in =sum

Phone number Provider Duration (min)
1001 Fastcom 2
1002 Fastcom 1
1004 Mobilecom 4
1008 Telecom 5
1001 Fastcom 3
1001 Fastcom 2
1003 Telecom 3
1004 Mobilecom 2
1008 Telecom 6
1002 Fastcom 1
I want to use one formula to get the sum of the duration of calls whose service provider is the provider for the phone number 1001. I hope this revised version is clearer than the previous one. Again, thanks to all who paid attention.
There are 14 rows. Column A contains numbers from 1 to 14. Column B contains Names of people(maybe repeated). Column C contains their preferred seasons (possible more than 1) and Column D contains how many days they do sports in that partucular season. I need one formula to get how many days are spent doing sports in the season(s) that is (are) preferred by Adam, which actually are Spring and Fall
Assuming data in rows 2 to 15 try this array formula
=SUM(IF(ISNUMBER(MATCH(C2:C15,IF(B2:B15="Adam",C2:C15),0)),D2:D15))
confirmed with CTRL+SHIFT+ENTER
In one formula I'm not sure. Personally I'd have a formula in each row of column E that is 0 or the value from D, then you can sum(e:e) instead.

Resources