Countif criteria and range are time values, excel 2016 - excel-formula

I am using Excel for Mac 2016.
I would like to count number of occurrences of time values e.g., 5:00pm in a column (A1:A100000). I would like to count the number of occurrences according to time value criteria in a different smaller column e.g., (B1:B10), which are also times. So I am matching time with time. For each row of the smaller column, I have tried the following:
=COUNTIF(A1:A100000,B1), which returns 0.
=COUNTIF(A1:A100000,"="&B1), which returns 0.
=COUNTIF(A1:A100000,">="&B1), which funnily enough, returns an actual number of occurrences, but is incorrect because I only want it to equal (B3), not be greater than.
Even when I hard code it in:
=COUNTIF(A1:A100000,">=5:00") works, =COUNTIF(A1:A100000,"=5:00") does not.
Because the time values in (B1:B10) are in serial form, e.g., 5:00pm, 6:00pm etc, even when I try:
=COUNTIFS(A1:A100000,">="&B1,A1:A100000,"<"&B2), it doesn't seem to return a correct value.
It does not seem to matter whether I have the range and/or formatted as Time, or General, nothing works! I'm sure it must be something simple that I am missing.

ok, so here is the ACTUAL formula, which looks nothing like the simplified one above. Basic COUNTIFS with Named ranges, and criteria. I have also uploaded a link to a screen shot of formula, and sample file.
=COUNTIFS(Appointment_date,">="&$C$5,Appointment_date,"<="&$C$6,Client_Name,"?*",Status,"Attended; ",Location,"*Richmond",Appointment_Day,C$9,Appointment_time,$B12)/$C$7
Screen shot:
https://drive.google.com/file/d/0B_m00iNatJANMWVuWGdLem5Vb1U/view?usp=sharing
Sample of file:
https://drive.google.com/open?id=0B_m00iNatJANMnE0UXZyUTctYk0
The real problem appears to be in the formula's inability to recognise specific times in the "Appointment time" column. I have outlined specifics within the document.
Thanks so much!

Related

Execute excel formula only for specific cells

I am trying to create a formula that checks for several things at the same time but I am having trouble with one part of it.
The formula is the following:
=IF(COUNTIFS($N$2:$N$17095,N3,$K$2:$K$17095,"<>"&"")>6,
IF((SUMPRODUCT(--(ROUND($K$2:$K$49,2)=ROUND(K3,2)))>9),"Always Late / Possible Automation",
IF(COUNTIFS($N$2:$N$17088,N3,$K$2:$K$17088,"<3.5")>0,"Delivered Earlier At Least Once",IF(COUNTIFS($N$2:$N$17088,N3,$K$2:$K$17088,">3.5")>6,"Always Late","False"))))
The first part checks how many entries in the range having the same value as it is in cell N3 have values different to blank and we want those to be more than 6.
Second part is the tough one, it is supposed to check how many values in the rounded range match the rounded value in cell K3. The issue is the formula checks the whole range and I want to check only for the values which match N3 (in essence like the CountIf works only for that value).
The rest is not so relevant.
Some example data:
![enter image description here][1]
As you see in the end of the table the formula with the rounding works but only because I have limited the data shown to 3 unique values in column N. Even here though if i have a blank it doesnt work becaus ei haven't considered it.
Thanks in advance.
Assuming you have Office 365 compatibility/Excel version, use a bunch of filters. To avoid an unwieldy formula I've extended ranges to maximum number of rows (customize as required)...
=LET(x_,$E$3:$E$25,a_,FILTER($E$3:$E$25,--(x_=E3)),b_,FILTER($B$3:$B$25,--(x_=E3)),IF(SUM(--(a_=E3)*(b_<>""))>6,IF((SUMPRODUCT(--(ROUND(b_,2)=ROUND(B3,2)))>9),"Always Late / Possible Automation",IF(SUM(--(a_=E3)*(b_<3.5))>0,"Delivered Earlier At Least Once",IF(SUM(--(a_=E3)*(b_>3.5))>6,"Always Late","False")))))
Note: filter does not appear to work too well within countifs for some reason (must be related to syntax RE: arrays vs. criteria TBC). Thus have replaced countifs(filter_range,X) eqn 'types' with sum(--(filter_range=X)) which works as intended.

COUNTIF dependend on cell format and input type?

Question: Is the COUNTIF function working inconsistent with different data types and cell formats?
The situation:
Column A contains manually created numbers (to be used in SAP). The numbers are 18 characters long, don't contain any non digit chars. The cell format has to be Text as we would face more issues down the line if it wouldn't. If I apply the formula =COUNTIF(A:A;A2) the result is as shown in column C. However this obviously not the correct result.
Another example with "real" test data from a system extract:
The issue here is, that the COUNTIF function sometimes returns the correct result, sometimes a wrong result. I cannot figure out why its working the way it does.
Also I did not find any satisfying result somewhere else on the Internet. If I missed something, please let me know.
As a side note: If I transfer the data into a PIVOT table it always shows the correct results.
Problem:
This will most likely be due to floating point errors.
Excel's COUNTIF function will try to handle these values in A column as numbers. Because Excel uses IEEE 754 specification on how to store and calculate floating-point numbers, Excel therefore stores only 15 significant digits in a number, and changes trailing digits after the fifteenth place to zeroes. Source.
For example:
541235479876536549 will become 541235479876536000
541235479876536550 will become 541235479876536000
541235479876536551 will become 541235479876536000
541235479876536552 will become 541235479876536000
That would mean your values are 3 digits too long to be handled accurately. In this example, the unique values will all be counted 4 times using COUNTIF.
Removing the last three digits from your string should therefor make the COUNTIF behave as expected. However, this will still give you unwanted results as you don't want to mess with the original data.
Solution:
If using a pivot table (which probably works as it should pick up the data as text) is not what you want, maybe you can use:
=SUMPRODUCT(--(A$2:A$11=A2))
Note: On a large dataset, array-formulas might slow down your
workbook significantly!
Furthermore, COUNTIF is not the only function that would suffer from this behaviour. The scope of this problem included functions like SUMIF, SUMIFS, COUNTIF, COUNTIFS, AVERAGEIF, and AVERAGEIFS. Source

How to find mathematical sum of positive and negative numbers in a single cell in Excel?

I have a column which has positive and negative numbers. I want to find the sum of them. All the values are in Number datatype.
When I use auto sum, I get 0.00 as my result.
Column Image
Also, the values in the column were populated from another columns (like =B2-C2)
However, if I copy and paste the values alone in another column and sum it up, I get the desired result
I agree with BigBen, it sounds like your data is in text format. Even though you change the format on the "Home" tab to "Number", it still might be read by Excel as text.
To quickly change all text "numbers" to real numbers, select the range of numbers and use the "Text to columns" feature under the "Data" tab.
Try making sure that your data is being interpreted as numbers.
For instance, use in E2 "=2*D2". You should get the corresponding number.
Do the same for all your sources cells.
(Given that you mention that these are results from calculations, I expect these to be actually numbers).
If any of the results gives you trouble, you already have the source of your problem.
If all the cells contain numbers, try using in F2 "=SUM(D2:D2)" and expanding the range one cell at a time.
You should be able to identify the source of the problem.
You may help others help you by making your workbook available somewhere online.
You don't need autosum, just SUM (which is anyway the function setup by autosum).

COUNTIF function shows a date instead of a number as a result

I was creating a frequency worksheet for the new classes i'll be taking this semester, but when i try to use the COUNTIF function as a sum of three different parameters, i always get a date (like 00/jan) as the result, not a natural number as i'd expect.
I've tried using the function COUNTIFS instead, only to achieve the same result.
The function i was trying to create is
=COUNTIF(B5:B23;"*criteria1*")+COUNTIF(B5:B23;"*criteria2*")+COUNTIF(B5:B23;"*criteria3*")
With COUNTIFS, it is as follows:
=COUNTIFS(B5:B23;"*criteria1*";B5:B23;"*criteria2*";B5:B23;"*criteria3*")
There is no error message, and all i want to get is a real number, that is, the real sum of those "criteria" appearing in the given interval.
Excel tries to be helpful and takes a guess at the data type of the formula cell.
Unfortunately, Excel often gets it wrong. Especially when the formula processes dates, Excel will often format the cell as a date, too, even though the result may not be a date at all.
Your only option is to manually apply a different format to the cell. General or Number will show the real number.

COUNTIF formula counts values that don't match

I'm using counting invoice numbers (text) in a table's column, but the Excel formula seems to be confusing some values.
I copied small sample of these - please refer to below:
The formulas are as follow:
=COUNTIFS(A1:A19,A1)
=COUNTIF(A1:A19,A1)
As you can see these invoice numbers differ and the results of these functions suggest as if all were the same.
I googled it for 1 hour but I didn't find such as issue as mine.
If anybody had any clue why could this behave in such way I'll be super grateful!
Rob
Each time you copy down this formula it will add 1 row to each. For example the second row of datas formula will be =COUNTIFS(A2:A20,A2). To lock these cells in the formula use $
Your formula should be =COUNTIFS(A$1:A$19,A1)
I've solved this myself:
ROOTCAUSE
Excel tried to be helpful and read these invoice numbers as actual numbers (despite these being defined already in Power Query as text)
Then, Excel fooled me and despite showing that it works on it as a string (I was evaluating the formula) it worked on it as number
Above means that it transformed exemplary "00100001010000018525" to 1.00001E+17, which cut down this to "100001010000018000" - that's the moment Excel stopped fooling around and showed that value in the formula bar.
I think I don't need to tell why countif perceived all these values as equal.
SOLUTION
I simply appended one letter after each invoice number to get e.g. "00100001010000018525a" what forces Excel to quit its gimmicks and games.
Case closed.
I suspect this is a bug in COUNTIF, or maybe by design.
However, to workaround this in the formula, without having to change your data, try adding a wild-card character:
=COUNTIF(A1:A19,"*"&A1)

Resources