Count names one time (per year) regardless of how many there are by year - excel

The problem is:
There is a table that gets data added to it each month. I use this data for many different pivot tables and reports, so I am not able to modify it. The user has requested that if its possible (and I assured him that it was) he would like to see two (2) single values of This Year and Last Year Doctors on the list.
The data looks something like this:
Doctor, In/Out, Date, Number
John Deaux Out 10/1/11 8
John Deaux Out 11/1/11 3
John Deaux Out 01/1/12 5
John Deaux Out 05/1/12 3
John Deaux Out 09/1/12 1
Billy White In 02/1/12 2
Mike Adams Out 06/1/11 6
Mike Adams Out 10/1/11 9
Mike Adams Out 01/1/12 1
Mike Adams Out 04/1/12 6
I would have 1 John Deaux for 2011, and 1 for 2012. The same for Mike Adams.
TY 2
LY 2
Now I only have to count the "Out"(s), so I have to be careful of that. Also, there is the chance that I would have to build this for the previous 12 months as well making it that much harder.
1 for John Deaux for the previous 12 months.
TY 2
LY 1
*TY: This Year - LY: Last Year

To do this manually:
Since you can't make any edits to the existing table, copy everything to a new table.
In the new table, add a column called Year. Use the Year() function to get the year out of the date cell.
Make another column called Count. Use If(A2="Out",1,0) where A2 is the cell in the In/Out column.
Copy the Doctor, Year, and Count columns to a new table.
Excel 2007 and above has a convenient tool called Remove Duplicates in the Data ribbon. Use that to remove the duplicates. This will keep you from counting a single doctor twice in the same year.
Create a pivot table, using Doctor as the row, Year as the column, and sum(count) for the value.

Check this, this will check the B column for the year 2012/2013 and count the distinct unique values in column A.
=SUM(IF(FREQUENCY(IF(YEAR(B1:B11)=2013;A1:A11);A1:A11)>0;1)) + CONTROL + SHIFT + ENTER
=SUM(IF(FREQUENCY(IF(YEAR(B1:B11)=2012;A1:A11);A1:A11)>0;1)) + CONTROL + SHIFT + ENTER

Related

How to check if a record exists based on month and persons name (where the name is duplicated)?

I have a data-set with some names and months, sample:
Name Month
Max 2
Sally 5
Max 1
James 11
Richard 9
Sally 9
I then have a table as such:
Month
Name 1 2 3 4 5 6 7 8 9 10 11 12
Max
Sally
James
Richard
How do I create a formula that can enter "Yes", or "No" for each month based on the person's name? For example, Max would have months 2 and 1 displaying "Yes", all other months displaying "No".
I can't think of how to do this...using an INDEX/MATCH function I can pull up the first month for "Max", but it won't register the second time his name shows up (it just matches the order of his name with where his data lies in the array, doesn't consider duplicates).
Is there a way to do this?
Thanks.
Assuming a data setup like this:
In cell E3 and copied over and down is this formula:
=IF(COUNTIFS($A$2:$A$7,$D3,$B$2:$B$7,E$2),"Yes","No")

List the next couple occuring birthdays in excel

Given the following data
A B
Steven 01/05/1958
Mike 05/12/1923
Bob 05/11/2001
Richard 10/22/1985
Maverick 12/25/1991
Ed 01/07/1954
I'd like to get a list in, let's just say the column D, containing the next couple birthdays that will occur.
So if today was 05/05/2016, I'd like to see
D E
Bob 05/11/2001
Mike 05/12/1923
My current approach (yet not working properly) is to create another column and have the days until the birthday calculated there, using this formula:
=DATE(YEAR(B2)+DATEDIF(B2+1;TODAY();"y")+1;MONTH(B2);DAY(B2))-TODAY()
Then I list the birthdays that come up in the next 5 days using:
=IF(ISERROR(INDEX($A$2:$C$5,SMALL(IF($A$2:$C$5<5,ROW($A$2:$A$5)),ROW(1:1)),2)),"",INDEX($A$2:$C$5,SMALL(IF($A$2:$A$5<5,ROW($A$2:$A$5)),ROW(1:1)),2))
I'd rather have the next 5 upcoming birthdays, no matter how far away from today they are.
Any Ideas how to achieve this without using makros?
Help is much appreciated!
To get the birthday difference from today in days :
=(DATEDIF($D$1,DATE(IF((DATE(YEAR($D$1),MONTH(B2),DAY(B2))>$D$1),YEAR($D$1),YEAR($D$1)+1),MONTH(B2),DAY(B2)),"D"))+0
The first BD from current date :
=VLOOKUP(SMALL(A2:A8,1)+0,A2:B8,2,FALSE)
Please see the img for more details :
Another approach would be to use the Advanced Filter. And you could automate it using VBA.
For the Criteria:
A2: =DATE(YEAR(TODAY()),MONTH(B6),DAY(B6))>=TODAY()
B2: =(TODAY()+$C$2)>=DATE(YEAR(TODAY()),MONTH(B6),DAY(B6))
Range is the number of days after today to show birthdays.
OK slightly different approach
Instead of counting days in a helper column, change the date in a helper column. Then sort that helper column for only the first 5 entries. This will show upcoming birthDAYS instead of birthDATES.
So assuming Names in column A, Dates in Column B, Column C is created with:
=DATE(YEAR(TODAY())+IF(TODAY()>DATE(YEAR(TODAY()),MONTH(B2),DAY(B2)),1,0),MONTH(B2),DAY(B2))
Now I was assuming no header rows and A1 was the first entry so to display the next 5 entries in column D I used:
=IF(ROW()<=5,SMALL($C$1:$C$6,ROW()),"")
Now this will not pull names but just the upcoming birthDAYS not birthDATES. The year being the difference between the two.
If you want to pull the names as well you can use the following:
=IF(D2<>"",INDEX($A$1:$A$6,MATCH(D2,$C$1:$C$6,0)),"")
Right now it will not return names of multiple people with the same date but there are ways around that. If you need that too let us know.
(A) (B) (C) (D) (E)
Steven 58/01/05 17/01/05 16/05/11 Bob
Mike 23/05/12 16/05/12 16/05/12 Mike
Bob 01/05/11 16/05/11 16/10/22 Richard
Richard 85/10/22 16/10/22 16/12/25 Maverick
Maverick 91/12/25 16/12/25 17/01/05 Steven
Ed 54/01/07 17/01/07
UPDATE
In order to deal with duplicate birthdays... try the following:
=IF(E5<>"",INDEX($A$1:$A$6,MATCH(E5,$C$1:$C$6,0)+COUNTIF($E$1:E5,E5)-1),"")
That was the entry for row 5. I tested it with the same birthdate, but I forgot to check for same birthday (different years).
UPDATE 2
NEW TABLE
The table below matches to formula from the last update
(A) (B) (C) (D) (E) (F) (G)
Steven 58/01/05 17/01/05 59 16/05/11 Bob 15
Mike 23/05/12 16/05/12 93 16/05/12 Mike 93
Bob 01/05/11 16/05/11 15 16/10/22 Richard 31
Richard 85/10/22 16/10/22 31 16/12/25 Maverick 25
Maverick 91/12/25 16/12/25 25 16/12/25 Ed 21
Ed 95/12/25 16/12/25 21
I inserted a column in D which shifted things right. The following was placed in D1.
=year(C1)-Year(B1)
In column G I had it lookup the age
=IF(E1<>"",INDEX($D$1:$D$6,MATCH(E1,$C$1:$C$6,0)+COUNTIF($E$1:E1,E1)-1),"")

Excel INDEX MATCH when one of multiple criteria is within a range of numbers

To identify duplicates in a large list of personal records, I'm replacing all names with a CONCATENATE of Name and Date of Birth (DOB). Here is the sheet I'm referencing (DOBs!):
DOBs! -----------------------------------------
C D E F G I K
Name Years Start End # Yrs DOB NewNameDOB
Sally Adams 2014-2014 2014 2014 1 1968-1204 Sally Adams1968-1204
John Agnew 2014-2014 2014 2014 1 1979-0419 John Agnew1979-0419
Bob Anderson 2013-2014 2013 2014 2 1965-0402 Bob Anderson1965-0402
Antonio Andrews 2014-2014 2014 2014 1 1955-0716 Antonio Andrews1955-0716
Julie Assan 2012-2014 2012 2014 3 1978-0805 Julie Assan1978-0805
On the main sheet (Employees!), each person has a row of data for each active year. Work 14 years, you have 14 lines of data to track.
Employees! -----------------------------------------
C D **E** F G H I J...
Year Name NewNameDOB Dept
2013 Julie Assan Julie Assan1978-0805 East
1998 Mike Rogers Duplicate in Same Year Main
1999 Mike Rogers Duplicate in Same Year Main
2000 Mike Rogers Mike Rogers1969-0510 Main
2001 Mike Rogers Mike Rogers1969-0510 Main
As mentioned, I need to separate duplicate names from 10395 records (like Mike Rogers and Mike Rogers). Employees! column E will now identify the employees as Julie Assan1978-0805 and Julie Assan1980-0131 (for example).
Today we take my first step, using the years they worked in order to solve 99% of the duplicates. After this, only a few duplicate names will be left who worked at the same time as each other, which I'll have to handle manually.
If the Employees! sheet has a 2013 record for "Julie Assan," then the first step is to check DOBs to find any Julie Assans who worked in 2013. My new column E in Employees! will take the current 2013 record of Julie Assan, and find any matches in DOB! where C (name) matches Julie Assan, E <= 2013, and F >= 2013. Usually, there will be only one match, and it will tell me that is Julie Assan1978-0805. Sometimes, there will be two Mike Rogers who worked during the same year, and it should tell me "Duplicate in Same Year".
On the Employees! sheet column E, I've started with this...
=index(DOBs!$k$2:$k$10395,match($d3&$c3,DOBs!$c$2:$c$10395& ??? ,0)
Not sure where to go with this formula, whether that means adding "IFs" or something different.
edited to explain in great depth
=IF(COUNTIFS(DOBs!C$2:C$10395,Employees!D2,DOBs!E$2:E$10395,"<="&Employees!C2,DOBs!F$2:F$10395,">="&Employees!C2)>1,"Duplicate in Same Year",INDEX(DOBs!K$2:K$10395,MATCH(TRUE,IF(DOBs!C$2:C$10395=Employees!D2,IF(DOBs!E$2:E$10395<=Employees!C2,IF(DOBs!F$2:F$10395>=Employees!C2,TRUE))),0)))
Enter as an array formula by confirming with Ctrl+Shift+Enter, then autofill down. It first checks for duplicates using COUNTIFS, and returns "Duplicate in same year" if it is. If there are not duplicates, it uses INDEX/MATCH to find the NewNameDOB.

Spotfire Custom Expression

In spotfire need to extract employee name for a particular quarter, how many added and left.
like we have
Employee_nm Quarter
Mohan 1
Rohan 1
Sohan 1
Mohan 2
Rohan 2
Joseph 2
output:-
When we select Quarter 2 result should
Left Add
Sohan joseph
An IronPython script could do this with a property control setting the quarter of interest.
User selects number 1-4 from a drop down menu which is stored in the document property 'lstQuarter' and connected to the script that does the calculation.
Pseudocode for the calculation:
Access the table
Fill listA with all the names from lstQuarter - 1
Fill listB with all the names from lstQuarter
Iterate through the lists comparing each name. Those in listA but not listB have been removed, those in listB but not listA have been added.
Write this information into a string, out to excel, wherever you want it.
If you want to update a table in Spotfire with this information you'll need to write it to Excel first and then replace the data table with it but this can all be scripted.
There is a solution to this issue that requires only a property control and 2 calculated values set into a text area plus 2 calculated columns.
Firstly, I extended the dataset to show a full year:
Employee_nm Quarter
Mohan 1
Rohan 1
Sohan 1
Mohan 2
Rohan 2
Joseph 2
Mohan 3
Joseph 3
Katelyn 3
Katelyn 4
Joseph 4
Wesley 4
Next, the calculated columns:
Case First([Quarter]) OVER ([Employee_nm])
when 1 then "Q1"
when 2 then "Q2"
when 3 then "Q3"
when 4 then "Q4"
end as [added]
-and-
if(Last([Quarter]) OVER ([Employee_nm])!=Max([Quarter]),
Case Last([Quarter]) OVER ([Employee_nm])
when 1 then "Q2"
when 2 then "Q3"
when 3 then "Q4"
when 4 then "Q1 Following Year"
end,"") as [left]
NOTE: The above only accommodates the given dataset but can be easily be extended to accommodate multiple years.
The Property control should be set up like so:
Finally, the calculated values:
UniqueConcatenate(if([added]='${Quarter}',Concatenate([Employee_nm]," added ",[added]),""))
-and-
UniqueConcatenate(if([Left]='${Quarter}',Concatenate([Employee_nm]," left ",[Left]),""))
NOTE: The above values will exhibit a leading comma in many cases due to the 'UniqueConcatenate()' function. These can be dealt with using text functions within your calculated values and that logic has been left out of this answer in the interest of readability.
I hope this helps.
You can insert a calculated column to identify the employees added/removed per Quarter:
Concatenate(If(Find([Employee_nm],Concatenate([Employee_nm]) OVER
(Previous([Quarter])))=0,"Added in this Quarter"),If(Find([Employee_nm],
Concatenate([Employee_nm]) OVER (Next([Quarter])))=0,"Removed from Next
Quarter"))
You can see result per Quarter by filtering on Quarter column.

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)

Resources