I wish to count the number of dates in a given column. The column has three possible values for a cell. A cell can be blank, have an "x", or have a date. I don't care what the actual date is, I just want to count the number of cells that have a date in them.
Use COUNTIFS()
=COUNTIFS(A:A,">=" & DATE(1900,1,1),A:A,"<=" & DATE(2045,12,31))
You can bracket the dates to what ever you want.
OR
You can do the negative.
If you are possitive the only three values possible are blank,x, and a date then:
=COUNTIFS(A:A,"<>",A:A,"<>x")
Using COUNT, it counts only if the cell value is numeric. The dates are internally numeric.
=COUNT(A:A)
Related
I want the code value in column B if the handset matches and the date is between the date from and the date to.
How the results should look:
Since you problem involve Date Range, therefore Vlookup & Index match is not possible to solve, I will use If + AND formula to solve your problem:
=IF(AND(E9>$G$3,E9<$H$3,F9=$E$3),$F$3,
IF(AND(E9>$G$4,E9<$H$4,F9=$E$4),$F$4,
IF(AND(E9>$G$5,E9<$H$5,F9=$E$5),$F$5,
IF(AND(E9>$G$6,E9<$H$6,F9=$E$6),$F$6,""))))
If you are able to add a column, one possible solution without using VBA would be to use a combination of SUMIFS and XLOOKUP formulas.
In column E, add a unique identification number (e.g., 1, 2, 3, 4, 5, etc.). You could reference the row number or manually fill down the numbers or whatever. It wouldn't matter as long as the values are unique and all numbers (no text).
Then, use a SUMIFS formula to sum Column E if (1) the handset number matches, (2) the date is greater than or equal to the start date, and (3) the date is less than or equal to the finish date. As long as there are no overlaps in the date ranges for each handset, this will return the unique ID number. Depending on the dataset, you might have to play with the less/greater than or equal to vs just less/greater than.
=SUMIFS(E:E,A:A,I2,C:C,"<="&H2,D:D,">="&H2)
Then, use the XLOOKUP to return the code based on the unique ID. In this example, I combined the SUMIFS and XLOOKUP in one formula, but you could also do it in two columns to provide better visibility.
=XLOOKUP(SUMIFS(E:E,A:A,I2,C:C,"<="&H2,D:D,">="&H2),E:E,B:B,"NOT FOUND",0,1)
Here's an example.
screenshot
I want to count a range where one of my criterion is NOT less than or equal to a date in another cell. But blanks are okay, so I can't just say the criterion is greater than that date in the other cell. Meaning that I want to count the cells that are either blank or after the given date. I've tried the following criterion but get a parse error because of the last, bolded criterion:
=countifs(Sheet2!$B:$B,"Example",Sheet2!$E:$E,<>"<="&B2)
B2=3/31/2017
Sheet2!E:E are cells either with dates entered or left blank
Thanks for any help.
If I understand what you want, add the blanks to those that meet your criteria:
For example:
=COUNTBLANK(theRange)+COUNTIF(theRange,">"&A2)
where theRange refers to, for example B2:B10
one more for good measure:
=countif(Sheet2!$B:$B,"Example") - countifs(Sheet2!$B:$B,"Example",Sheet2!$E:$E,"<="&B2)
complementing #BigBen's response.
Try this:
=countifs(Sheet2!$B:$B,"Example",Sheet2!$E:$E,">="&B2)+countifs(Sheet2!$B:$B,"Example",Sheet2!$E:$E,"")
I want to count the cells that are either blank or after the given date
Try this:
=SUMPRODUCT(--($A$1:$A$16>E2)+--($A$1:$A$16=""))
This is how it works:
--($A$1:$A$16>E2 will return an array of 1 and 0, depending if cell value is *greater than value in E2. In this case we'll get {0;0;0;0;0;0;0;0;1;1;1;1;1;1;1;1}
--($A$1:$A$16="") will return an array of 1 and 0, depending if cell is blank or not. In this case we'll get {0;0;0;1;0;1;0;0;0;0;0;0;0;0;0;0}
+will sum up both arrays, so we get {0;0;0;1;0;1;0;0;1;1;1;1;1;1;1;1}
SUMPRODUCT will sum up that array into a single number, in this case, 10.
Other cases:
Need help figuring out how do I sum all the values inside a certain criteria and a user input date. Assuming that the criteria is 115 how do I add to the function the capabilty to sum according to a date range of choice?
I can get the criteria sum just fine with =SUMIFS(B2:B21;C2:C21;"115") but i cant figure out something to add the date to this function.
Table Example
Any help is aprecciated! Thanks in advance!
JonhDoe
Use:
=SUMIFS(B:B;C:C;"115";A:A;">=" & E3;A:A;"<=" & E5)
NOTE
This assumes that the "Dates" in column A are in fact true dates and not strings that look like dates. It appears that your "numbers" are stored as text.
I better show you. This is how my list looks like:
And this is how I want it to be:
Basically, in the first picture I have different date ranges, for each date range I have a those two metrics, Sessions and Users and the final result should be a sort of explosion of all date ranges into single dates, considering that certain dates can be included in more than 1 date ranges (e.g. date 2017-08-12) is included in both first and second row.
And last but no least, the end date shouldn´t be counted.
Can someone help me out?
Thanks a million
A.
This is the outline of a solution:
Split each from/to date in your input table into its 2 constituent dates. You will need to use the string functions (LEFT, RIGHT and MID) to extract the numbers for the year, month and day values. These will still be strings of characters, so use the VALUE function to convert them to actual numbers and then use the DATE function to assemble them into a proper date value in Excel. (You may need to format your results using a date format, as Excel stores its dates as number of days since 01/01/1900, so 11/08/2017 is held in Excel as 42958.) Add as many helper columns as you need to your input table to achieve this.
Subtract 1 from each end date, this corrects the dates ranges so that the end date is included.
The first start date and the last end date define the range of output dates. So start your output table with the first date and in the cell below use a formula to add 1 to this date and copy the formula downwards until you get to your last possible output date.
To get the results for each possible output date, you need to find
which date ranges it belongs to. It belongs to a date range if it is
greater than or equal to the range's start date and less than or
equal to the end date. However, rather than comparing each output
date with individual start and end dates it is possible to compare
each output date with all the start and all the end dates at once. An expression such as A10>=E2:E7 generates an array of 6 elements with values
TRUE and FALSE according to whether A10 is greater than or equal to
E2, E3, E4, E5, E6 and E7 respectively. So, you can use this approach to generate an array of TRUE/FALSEvalues showing whether a particular output date is greater than or equal to (ie on or after) each range's start date. Similarly, you can get an array showing whether the same output date is less than or equal to (ie on or before) each range's end date.
The versatile SUMPRODUCT function can now be used to combine the arrays and the relevant sessions/users values from the input table to get the relevant values for the output date. For example, if the start dates are in E2:E7, the end dates in F2:F7, the sessions in B2:B7 and the output date in A10 then a sutable formula for determining the number of sessions to attribute to the output date would be =SUMPRODUCT(($A10>=$E$2:$E$7)*($A10<=$F$2:$F$7)*(B$2:B$7)). This formula could be copied to give results for all output dates and, assuming the input data for users is in C2:C7, it will also give the results for users if copied into the column adjacent to the sessions results. In this formula, the TRUE and FALSE values are effectively converted to 1 and 0, respectively.
A few points: (i) if you don't know how dates work in Excel then find out, it makes tasks such calculating the number of days between two dates or the date n days before/after a particular date extremely easy using simple arithmetic; (ii) don't confuse strings of text which look like dates with dates that can be manipulated arithmetically in Excel; (iii) I believe there are some errors in your example - 16/08/2017 is a date in two of your input ranges and should have results of (2,2) not (1,1) and 17/08/2017 is similarly in error.
I have used this approach in the illustration below and, to test its robustness, I have added an extra row of input data which has sessions different from users and which yields one date (19/08/2017) which does not match to any input range.
The output date range was generated as follows:
Cell A10: use formula =E2
Cell A11: use formula =1+A2
Cells A12, A13, ... copy formula in cell A11
I'm trying to count the number of instances where a date is entered in a column in Excel. I can't seem to construct the right CountIf statement. I'm trying to count the number of times an instance a date is greater than or equal to 1/5/2015.
=COUNTIF(L:L, >="01/05/15")
I see two issues here
Enclose the comparison operator in quotes
Specify the date to compare to as a date not a string
Better yet put the comparison date in a cell (let's say A1). Formula becomes
=COUNTIF(L:L, ">=" & A1)
Formula:
=COUNTIF(L:L, ">=01/05/15")