Counting unique values in a column that matches multiple criteria in a single column - excel

I'm trying to count how many values in column A multiple multiple criteria that are mixed in column B. I was able to do this using a helper column (column C). To better get the idea, please see below:
Row Column A Column B Column C
Day Shift Helper
1 Monday Worked AM Worked PM
2 Tuesday Worked AM
3 Wednesday Worked AM Worked PM
4 Monday Worked PM
5 Wednesday Worked PM
Column A contains days from Monday to Wednesday, column B contains shifts while column C contains a formula to return "Worked PM" if that day also has a "Worked PM" somewhere below. Basically, Monday and Wednesday has these in rows 4 and 5.
Formula for cell C1 is =IF(B1="Worked PM","",IF(COUNTIFS($A$1:$A$5,$A1,$B$1:$B$5,"Worked PM")>0,"Worked PM",""))
The reason why I have this helper column is because I want to count the days that have both "Worked AM" and "Worked PM" on them. In our example, the count formula should return 2. I used the following formula, which is working perfectly: =COUNTIFS($B$1:$B$5,"Worked AM",$C$1:$C$5,"Worked PM")
However, I wish to completely eliminate the helper column (column C), which I have failed to do ever since. I tried making use of SUMPRODUCT, COUNT+MATCH and COUNTIFS. I've seen tutorials on how to do this from different Excel help sites, but I've seen nothing that matched my concern. They were "close" (not sure), but when I reconfigure them, I always fail.
I've turned to here as my last stop before giving up. I want to ask if what I'm actually doing is impossible. If it is possible, I would as well seek your guidance on how can I arrive on the solution. Thanks in advance! :)

This will replicate the results from your helper column method. Enter as an array formula (ctrl+shift+enter):
=SUM(--IF(B2:B6="Worked AM",IFERROR(MATCH(A2:A6,IF(B2:B6="Worked PM",A2:A6),0),0)>0))
But unless you have duplicate row entries, wouldn't the count simply equal the number of repeats you have in column A? You don't have to enter this as an array formula:
=SUM(--(FREQUENCY(MATCH(A2:A6,A2:A6),ROW(A2:A6)-ROW(A2)+1)>1))

Related

SUMPRODUCT difference between two dates for THIS WEEK entries only

I have a column D containing all the Dates in DD/MM/YYYY format, and I would like to show the count of missed days for THIS WEEK values only from all the entries in column D.
In other words, if there is a difference between two Dates in column D and it occured this week, I would like to count it.
I have below formula to calculate "Total days missed" between first and the last entry in Dates column D, however I can't adopt this formula to display "Days Missed" for THIS WEEK only entries.
=SUMPRODUCT(--ISNA(MATCH(ROW(INDIRECT(MIN($D$18:$D$500)&":"&MAX($D$18:$D$500)));$D$18:$D$500;0)))
Sample of data set.
Please help, thanks.
For O365, in accord with your statement that there can be multiple entries of one date, I suggest the following (assuming your dates are real dates and not text strings that happen to look like dates):
Total Missing Dates
=MAX($D$18:$D$500)- MIN($D$18:$D$500)+1-COUNT(UNIQUE($D$18:$D$500))
Missing Dates THIS WEEK obviously, you'll need to define the first and last dates of THIS WEEK
=7-COUNT(FILTER(UNIQUE($D$18:$D$500),(UNIQUE($D$18:$D$500)>=wkStart)*(UNIQUE($D$18:$D$500)<=wkEnd)))
If your week starts on Monday, you can calculate:
wkStart: =TODAY()+1-WEEKDAY(TODAY()-1)
wkEnd: =wkStart+6
More generally, to return a particular day of the week prior to someDate (or wkStart):
wkStart = someDate - WEEKDAY(someDate - DayOfWeek)
where DayOfWeek is: Sunday=1 Monday=2 , etc
So, making someDate = TODAY()+1 ensures that if today is monday, it will return today and not the monday from a week ago.
HINT: It might be more convenient to define wkStart and wkEnd as a Named formula.

Count the number of full weekends worked (Sat&Sun) in an excel shift-work roster for each staff member over the current calendar year

I have an Excel rostering spreadsheet for shift workers and need to count the number of full weekends rostered (Sat&Sun) on/off for each staff member over the current calendar year.
I have tried several formulae, tried named ranges, countif, countifs etc. but am having problems counting identical values in two consecutive columns (days) in the same row i.e. Saturday and Sunday. Single day counts (such as number of Sundays worked) is no problem but I'm stumped with how to calculate the number of weekends when both days are rest-days, for example
The following works well for the number of single Rest Days (RD) falling on a Sunday but I need to determine the number of weekends in which both days(sat & Sun) are Rest Days.
=SUM(COUNTIFS(ROSTER!$M$17:$PM$17,"Sun",ROSTER!M28:PM28,{"RD"}))
The above is a small sample taken from a worksheet that contains a complete year's roster. Each roster is a two week block,starting on Sunday, with a column titled "RDFN" between the Sat and Sun at the end and beginning of the next fortnight.
Edit 2
As confirmed you want to count the number of weekends where both Sat and Sun are RD (Rest Day) in a given time frame.
I have revised my SUMPRODUCT formula (which works as COUNTIF in this case) to find the result for Jane. Simply drag it down to apply to other employees:
=SUMPRODUCT(((B5:AH5&C5:AI5)="RDRD")*((B$2:AH$2&C$2:AI$2)="SatSun"))+SUMPRODUCT(((B5:AH5&E5:AK5)="RDRD")*((B$2:AH$2&E$2:AK$2)="SatSun"))
This formula is using two SUMPRODUCT formula and adding the results from the two. Both SUMPRODUCT formula followed the same logic.
It will work in the case you have two columns between each fortnight, and it is actually slightly shorter than my previous
solution.
Let's take Jane's data for example. Imagine you have inserted four helper rows.
The formulas in the first helper row are B$2&C$2, C$2&D$2, and so on so forth till AF2&AG2, which represents SunMon, MonTue, TueWed, etc.
The formulas in the second helper row are B5&C5, C5&D5, and so on so forth till AF5&AG5, which represents RD8 M, 8 M14 A, 14 A14 A, etc.
So the first SUMPRODUCT formula is counting the number of RDRD in the second helper row when the corresponding position in the first helper row is returning SatSun.
First Part =SUMPRODUCT(((B5:AH5&C5:AI5)="RDRD")*((B$2:AH$2&C$2:AI$2)="SatSun"))
However the above formula is not working in situation where the last Sat of the first fortnight and the first Sun of the following fortnight are both RD because there are two columns in between which will not return RDRD in the second helper row so the match will fail.
To overcome the problem, I have to use a second SUMPRODUCT formula with the help from another two imaginary helper rows.
The formulas in the third helper row are B$2&E$2, C$2&F$2, and so on so forth till AF$2&AI$2, which represents SunWed, MonThu, TueFri, etc.
The formulas in the forth helper row are B5&E5, C5&F5, and so on so forth till AF5&AI5, which represents RD14 A, 8 M9 M, 14 A6 M, etc.
The second SUMPRODUCT formula is also counting RDRD in the forth helper row when the corresponding position in the third helper row is returning SatSun.
Second Part =SUMPRODUCT(((B5:AH5&E5:AK5)="RDRD")*((B$2:AH$2&E$2:AK$2)="SatSun"))
Adding the results from both parts will give you the total number of weekends where both Sat and Sun are RD as shown below:

In Excel how to count between date1 and date2 that have cells in row that contain text?

I need to choose cells in one column that are between two dates, and then based on the rows that contain those dates, choose cells in another row that also contains content.
I didn't use ISBLANK because it counts a formula yet an empty cell as a not-blank. Instead check if there is content by "*".
Here is what I came up with, but instead of returning the number of cells, instead this returns TRUE (which obviously isn't what I want).
In the formula below I am assuming:
C:C is the whole column containing DATES.
E:E is the whole column containing CONTENT.
The date range in this case is January 1, 2018 to January 31, 2018.
"*" means is there is content in the cell
=IF(AND(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&"2018-1-31"),COUNTIF(E:E,"*"))=0,"",AND(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&"2018-1-31"),COUNTIF(E:E,"*")))
My goal is to:
count the numbers of the cells in column E that are between the dates in column C
if the whole formula is 0, then return a blank.
See this picture of a sample excel sheet to make my intent clear:
How can I get my formula working so it does as needed?
SOLUTION
Hi all, so thanks to #girlvsdata, we have a working solution. I had to do a couple edits to her code to work for my uses, but her formula overall works perfect. Here is the solution:
To choose all cells in column E that are not blank, in between the date range of all of January (unknown end date) based on the adjacent C column if that is your date column, then the solution is:
=IF(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&EOMONTH("2018-1-1",0),E:E,"*")=0,"",COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&EOMONTH("2018-1-1",0),E:E,"*"))
Note that "2018-1-1" is January 1 2018, and EOMONTH("2018-1-1",0) is the last valid day of January in the year 2018 (in this case, 31, but if it is different another year (e.g. for February this works for leap years too) then it will be that last day). Also it eliminates the need to calculate which is the last day or every month, as well as months that have changing end dates dependent on the year (e.g. Feb). This is important to eliminate a margin of error.
The only thing you have to do to change the month is only change e.g. -1- (Jan) to -2- for Feb, or change the year for other years. With this formula you can ignore the day part.
If the answer is 0 (no cells have any content in between the range), then the cell is blank instead of 0. (GOod for when you want to create a sheet checking future dates for future reference when more rows are added to the sheet.
It also works across different sheets, just use, say your other sheet is called "Tracker" then use Tracker!C:C and Tracker!E:E. Hope it helps!
Thank you all! :D
(Please note: My local date format is day, then month)
With the data laid out as in your example above:
A B
1 Dates |Content
------------+-------
2 1/01/2018 |
3 2/01/2018 |123456
4 3/01/2018 |
5 4/01/2018 |12398
6 5/01/2018 |484
7 6/01/2018 |1538
8 7/01/2018 |
9 8/01/2018 |
10 9/01/2018 |
11 10/01/2018 |14648
12 11/01/2018 |
13 12/01/2018 |145615
14 13/01/2018 |
And with the date range in cells D2 and E2:
Date Start Date End
2/01/2018 7/01/2018
This formula returns the count:
=COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0")
This will depend on whether your numbers in Column B are formatted as text or number. If they are formatted as numbers, the above formula will work. If they are formatted as text, replace the last section ">0" with "*".
This formula adds the conditional part of your question:
=IF(COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0")=0,"",COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0"))
(If the formula returns 0, show blank)

excel nearest due date

I have a row with dates and below it I have an empty row where I can type a "C" on any number of cells wanted or needed to get the dates above it, but I only get the first C, so what I am trying to do is actually ignore every "C" that I have wrote that correspond to past dates from today and only give me the closer one or next one from today.
For example: lets say that today is July 1 2018, so I have row 1 with a series of dates like A1=June 30 2018, B1= July 1 2018, C1=July 2 2018, D1=July 3 2018, etc and in row2 I have typed C on A2, C2 and E2 so with HLOOKUP it returnsJune 30 2018`, but I dont want that since that date is now in the past, I want to get the next and more close date after the present day so it should be C2 that is July 2 2018, and so on since the today formula will update as the days pass.
This is to get the next checking date on a project cronogram so all the dates are defined but the result as for each task should be automatically updating to stay relevant for the scehdule, so past dates just dont make any sence to be the results showed on the gantt table diagram, and yes I know it is easy as just to be deleating the "C" that correspond to past dates, but then what is the point of excel then?
I'll go out on a limb here.... you want to find the first C in row 2 after todays date which is in row 1.
MATCH will tell you which column todays date is in: MATCH(TODAY(),$1:$1,0) returns 3 as 2nd July is in C1.
INDEX will return a reference to the cell below todays date when used in conjunction with MATCH: INDEX($2:$2,,MATCH(TODAY(),$1:$1,0))
COUNTA will tell you the last column that's populated with dates in row 1: COUNTA($1:$1) returns 9 in my case as I've put dates from A1:I1.
Use INDEX again to return a reference to the last cell in row 2. INDEX($2:$2,,COUNTA($1:$1))
Stick both INDEX's together to get a range reference from todays date to the end of you data: INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)) - this returns an error as it's returning the reference to multiple cells.
Now find the first C in the referenced range: MATCH("C",INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)),0) returns 1 as I've got a C in 2nd July.
Add the column that todays date is on to the column that was returned (and minus 1 for the hell of it). SUM(-1,MATCH(TODAY(),$1:$1,0),MATCH("C",INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)),0)) returns the column number of the first C on or after todays date.
Use that number to return a reference to the date in row 1: =INDEX($1:$1,,SUM(-1,MATCH(TODAY(),$1:$1,0),MATCH("C",INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)),0))).
So your final formula is:
=INDEX($1:$1,,SUM(-1,MATCH(TODAY(),$1:$1,0),MATCH("C",INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)),0)))
Bit long, and I'm sure it can be done in a much shorter formula.
Edit: I also agree with Rawrplus - you could've explained it a bit better.

Excel function to calculate pairwise date difference

I have a excel sheet with all employees of my company. This list also includes the sick days of each employee. I want to calculate the sick days of each year.
My excel sheet looks like this (shortened version):
A B C D E F G ...
1 Name From To From To From To ...
2 Max 2015/06/15 2015/06/16 2016/08/17 2016/08/17
3 Sarah 2016/01/20 2016/01/20
4 Phil
...
Explanation: Max was sick for two times. First from 2015/06/15 to 2015/06/16 and second from 2016/08/17 to 2016/08/17. Every time he gets sick the table is expanded to the right. Sarah was sick only on 2016/01/20 and Phil wasn't sick.
Now, I want to calculate the sick days of a year.
I could do something like
A B
10 2015 Sum of sick days in 2015
11 2016 Sum of sick days in 2016
So what needs to be done is:
check if date is in the right year
pairwise calculation of networkdays of all dates in a row, that means
=SUM(NETWORKDAYS(B2;C2)) for 2015 and
=SUM(NETWORKDAYS(D2;E2);NETWORKDAYS(B3;C3)) for 2016.
But it should work more dynamically. I only want to choose the matrix, e.g. A1 to I8 for each year and the rest should be calculated automatically. Does anybody know how I can do that?
You can use the below formula. (paste this in the cell B10
=SUMPRODUCT((YEAR($B$2:$N$8)=$A10)*(MOD(COLUMN($B$2:$N$8),2)=0)*(($C$2:$O$8-$B$2:$N$8)+1))
Copy the above cell into B11. It should work.
The following seems quite unruly:
=IF(YEAR(C2)=A10,NETWORKDAYS(B2,C2))+IF(YEAR(G2)=A10,NETWORKDAYS(F2,G2))+IF(YEAR(K2)=A10,NETWORKDAYS(J2,K2))+IF(YEAR(C3)=A10,NETWORKDAYS(B3,C3))+IF(YEAR(G3)=A10,NETWORKDAYS(F3,G3))+IF(YEAR(K3)=A10,NETWORKDAYS(J3,K3))+IF(YEAR(C4)=A10,NETWORKDAYS(B4,C4))+IF(YEAR(G4)=A10,NETWORKDAYS(F4,G4))+IF(YEAR(K4)=A10,NETWORKDAYS(J4,K4))
Alternatively you could either write a macro to loop through the data or add an additional two columns in between each From and To column. D2 would be
=IF(ISBLANK(C2),"",YEAR(C2))
and copy down. E2 would be
=IF(ISBLANK(C2),"",NETWORKDAYS(B2,C2))
and copy down. E11 would be
=SUMIF(D2:D4,$A11,E2:E4)
and copy across to I11 and M11 etc. You can then just
=SUM(C11:M11)
These new columns can be hidden if you needed.

Resources