excel formula help on counting unique dates between specified dates - excel

I am writing an excel formula for work. I have an updating sheet that counts for the month's output for each person. I want to keep track of how many days they have worked. by counting the unique dates they input into the sheet but only between the month dates placed on the master lookup form. ex
the month is 01/01/2019 - 01/01/ 2019 column a contains dates entered by employee cell e2 contains months beginning cell d2 contains months end found by eomonth. I want to search dates in column a for dates between e2 - d2 and output in e3 number of days worked.
=if(COUNTIFs(J3:J,J3:J&"",J3:J,">="&N2,J3:J,"<="&O2) = 0 ,"no days worked",SUMPRODUCT((J3:J<>"")/COUNTIFs(J3:J,J3:J&"",J3:J,">="&N2,J3:J,"<="&O2)))
is what I have so far. it keeps giving me the second part of sumproduct cannot be zero. but that formula is giving me 4 if used by itself based on the data set I am giving it. so I'm not sure where I am going wrong.

This is what I came up with.
=SUM(--(FREQUENCY(OFFSET(INDEX(Dates,IFERROR(MATCH(Dstart,Dates,0),MATCH(Dstart,Dates,1)+1)),0,0,COUNTIFS(Dates,">=" & Dstart, Dates,"<=" & Dend)),OFFSET(INDEX(Dates,IFERROR(MATCH(Dstart,Dates,0),MATCH(Dstart,Dates,1)+1)),0,0,COUNTIFS(Dates,">=" & Dstart, Dates,"<=" & Dend)))>0))
In a largely unsuccessful bid to make this formula more readable a created named ranges as follows.
Dstart = your D2
Dend = your E2
Dates = your J:J
You may replace the names with the addresses. However, I do not recommend the use of J:J because these 3 characters represent 1.4 million cells referenced repeatedly. If your data is of smaller size I recommend to stick with a named range for them and limit the size of that range somewhat.
Note that the formula is bloated because it counts unique values only. Its action, in a nutshell, is to find the first cell to match Dstart, then establish the last cell by counting how many entries there are and, finally, count unique items within that range.

Related

How do I write an excel formula to count the number of a value in one column based off of a date in another column?

I have a worksheet and I'm trying to do a simple Count function, probably a countif but I'm unsure how to go about writing the formula.
I have two columns that I'd like to use for this formula.
Column N - I would like to filter for the Criteria of "C" or anytime a cell has a value of C
Column 0 - This column has dates filled in (short date format).
I would like to get a count of every C for each month, as simple as that.
In this example I filtered the date for May of 2017 and filtered for C under the Check column. We can see that there are 12 instances of C showing in the month of May 2017.
Does anyone know how to structure a formula that I would be able to Count the Number of C's for every month into the foreseeable future?
I figured out how to count the total present in a date range but unsure of how to add the date range plus Column N (Check) every time "C" is present in the cell.
=SUMPRODUCT((O:O>=DATEVALUE("5/1/2017"))*(O:O<=DATEVALUE("5/31/2017")))
Try this
=COUNTIFS(O1:O100,">="&A1,O1:O100,"<"&B1,N1:N100,"C")
Where A1 has the start date and B1 has the end date for that month. You can use DATEVALUE() instead of A1 and B1. Change as applicable
Screenshot
If you want to use SUMPRODUCT then see this
=SUMPRODUCT((O:O>=DATEVALUE("1/5/2017"))*(O:O<=DATEVALUE("30/5/2017"))*(N:N="C"))
In another column (lets say 'P' for example) I would insert a formula to give you the month number =Month(P7) - this will return 5 for May.
I would then use COUNTIFS (Like COUNTIF but it uses multiple criteria) to count where column N contains 'C' and column 'P' contains '5'.
=COUNTIFS(N:N,"C",P:P,5)
Try this....you need to select the entire Column B and named the column as 'Date'.enter image description here

Count if a range of cells contains a certain month

I have a list that contains dates in M/DD/YYYY format.
In another sheet (see first image), i want to be able to calculate how many times a certain month appears in that list.
The formula i thought would work is
=COUNTIFS(*date range sheet&cells*,ISNUMBER(*date range sheet&cells*),*date range sheet&cells*,(MONTH(*date range sheet&cells*)=1))
In this case, the 1 would be for January, 2 for February and so on.
I am using a countifs because i have another if statement already worked out that i need to combine with this one: (*Date range sheet&another column*),"Loss")
Thank you all
With dates in column A, in C1 enter:
=SUMPRODUCT(--(MONTH($A$1:$A$27)=ROW()))
and copy down through C12:
C1 are the January countsC2 are the February countsetc.

SUMIF for multiple spreadsheets with text conditional

I have an Excel book with around 100 spreadsheets within the book. Each spreadsheet is an application of certain products. The very last spreadsheet is a total tally for the year for each product we use. The SUMIF formula I am using is:
=SUMIF('Jan 1:Dec 31'!B5:B14,"Name of product",'Jan 1:Dec 31'!D5:D14)
So when the Name of the product is used in B5:B14 in all spreadsheets from first (Jan 1) to last (Dec 31) I want to sum its value from the D5:D14 cells in all spreadsheets from first (Jan 1) to last (Dec 31).
The problem is that I just end up getting a #VALUE error. I have also tried inputting the formula by holding Ctrl+Shift. Nothing seems to work.
You could use the indirect formula and have Jan 1 in cell A1, and then in B1 have formula:
= sumif(indirect(A1&"!B5:B14"),"Name of product",indirect(A1&"!D5:D14"))
Then you'd put Jan 2 in cell B1 and copy the sumif formula down.
Note that this assumes structure is consistent on each tab and that number of rows is consistent on each tab as well (or you can make the bottom of the range an arbitrarily high number like row 50,000)

Excel Convert Now() to a Number to compare against another Number

I am trying to use some logic in a spreadsheet without any macros.
First I have a sinle cell that gives the date and time. I then used the custom format on that cell to just show the "h". So only hour numbers 1 through 24 appear in this cell. (e.g. at 3:20 p.m. I get 15 in the cell). (Cell # A:1)
=now()
Second, I have a separate single column with 24 rows numbered 1-24 (Cell #'s B1:B24)
I have a third column that has logic that states "Night" shift" for numbers 23 & 0-6; "Day Shift" for numbers 7-14; and "Mid Shift" for numbers 15-22) (Cell #'s C1:C24)
=if($A$1=B1,"Night Shift","")
However, the third columns all appear blank even tough one should appear. I tried changing A1 using text(A1,"#") but I get the serial number. Is there an easy way to dynamically have a value in column C show what shift based off the hour of the day in cell A1. Column D simply concatenates all 24 cells since there will only be one number ever. (Cell # D1). Thanks for any help.
You could use a LOOKUP formula to return the shift based on a time/date value in A1, e.g.
=LOOKUP(HOUR(A1),{0,7,15,23;"Night","Day","Mid","Night"})&" Shift"
Changing the format of the cell containing the date and time does nothing to the actual contents of the cell. It will still contain a value such as 43706.75 (number of days and fractions of days since 1/1/1900).
If what you want to do is determine the shift for the date/time in A1, you could use a formula like:
=IF(AND(HOUR(A1)>=7,HOUR(A1)<15),"Day Shift",IF(AND(HOUR(A1)>=15,HOUR(A1)<23),"Mid Shift","Night Shift"))
And similar logic if you need to apply different multipliers for the salary.
If you need something else, be more specific.
By doing =now() without any formatting you get the Date and the Time. Then in cell A2 do
=(A1-INT(A1))*24
Then in cell A3 do
=INT(A2)
This gives you the hour number extracted from a date format so a comparison can be made in column C against the numbers in column B. Thanks.

Count number of occurrences by month

I am creating a spreadsheet with all my data on one sheet and metrics on the other.
On sheet 1 in cells A2:A50 I have the dates in this format (4/5/13). On sheet 2 in cell E5 I have April and I want it to total the number of PO's created in F5.
How can I do this?
I have tried using
=COUNTIF('2013'!$A$2:$A$50,'2013 Metrics'!E5).
I have a feeling that since my range is in 4/5/13 format and my criteria is April that won't work.
I was able to use this formula for total spend by month:
=SUM(IF(MONTH('2013'!$A$2:$A$19)=4,'2013'!$D$2:$D$19,0))
but not luck with how many PO's by month.
Use a pivot table. You can manually refresh a pivot table's data source by right-clicking on it and clicking refresh. Otherwise you can set up a worksheet_change macro - or just a refresh button. Pivot Table tutorial is here: http://chandoo.org/wp/2009/08/19/excel-pivot-tables-tutorial/
1) Create a Month column from your Date column (e.g. =TEXT(B2,"MMM") )
2) Create a Year column from your Date column (e.g. =TEXT(B2,"YYYY") )
3) Add a Count column, with "1" for each value
4) Create a Pivot table with the fields, Count, Month and Year
5) Drag the Year and Month fields into Row Labels. Ensure that Year is above month so your Pivot table first groups by year, then by month
6) Drag the Count field into Values to create a Count of Count
There are better tutorials I'm sure just google/bing "pivot table tutorial".
For anyone finding this post through Google (as I did) here's the correct formula for cell F5 in the above example:
=SUMPRODUCT((MONTH(Sheet1!$A$1:$A$50)=MONTH(DATEVALUE(E5&" 1")))*(Sheet1!$A$1:$A$50<>""))
Formula assumes a list of dates in Sheet1!A1:A50 and a month name or abbr ("April" or "Apr") in cell E5.
Make column B in sheet1 the dates but where the day of the month is always the first day of the month, e.g. in B2 put =DATE(YEAR(A2),MONTH(A2),1). Then make E5 on sheet 2 contain the first date of the month you need, e.g. Date(2013,4,1). After that, putting in F5 COUNTIF(Sheet1!B2:B50, E5) will give you the count for the month specified in E5.
I would add another column on the data sheet with equation =month(A2), then run the countif on that column... If you still wanted to use text month('APRIL'), you would need a lookup table to reference the name to the month number. Otherwise, just use 4 instead of April on your metric sheet.
use count instead of sum in your original formula u will get your result
Original One
=SUM(IF(MONTH('2013'!$A$2:$A$19)=4,'2013'!$D$2:$D$19,0))
Modified One
=COUNT(IF(MONTH('2013'!$A$2:$A$19)=4,'2013'!$D$2:$D$19,0))
AND USE ctrl+shift+enter TO EXECUTE
Recommend you use FREQUENCY rather than using COUNTIF.
In your front sheet; enter 01/04/2014 into E5, 01/05/2014 into E6 etc.
Select the range of adjacent cells you want to populate. Enter:
=FREQUENCY(2013!!$A$2:$A$50,'2013 Metrics'!E5:EN)
(where N is the final row reference in your range)
Hit Ctrl + Shift + Enter
Sooooo, I had this same question. here's my answer: COUNTIFS(sheet1!$A:$A,">="&D1,sheet1!$A:$A,"<="&D2)
you don't need to specify A2:A50, unless there are dates beyond row 50 that you wish to exclude. this is cleaner in the sense that you don't have to go back and adjust the rows as more PO data comes in on sheet1.
also, the reference to D1 and D2 are start and end dates (respectively) for each month. On sheet2, you could have a hidden column that translates April to 4/1/2014, May into 5/1/2014, etc. THen, D1 would reference the cell that contains 4/1/2014, and D2 would reference the cell that contains 5/1/2014.
if you want to sum, it works the same way, except that the first argument is the sum array (column or row) and then the rest of the ranges/arrays and arguments are the same as the countifs formula.
btw-this works in excel AND google sheets. cheers

Resources