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

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.

Related

Find minimum date in row with multiple data types in Excel

I am trying to find the minimum date in a row that has both dates and number data types. I tried to use the MINIFS function but that still produces the number value as the minimum, rather than the date. I am restricted to doing this as an in-cell function, rather than in VBA. Also, the data structure is a bit wonky, I know, but it can't be changed.
=MINIFS(A2:C2,A2:C2,CELL("format",A2:C2)="D4")
When I enter =MIN(IF(A6:C6>40000,A6:C6)) I get a #Value error. Excel doesn't like the range before the > symbol.
Remember that dates in Excel are calculated as number of days starting from January 1st, 1900.
Thus, if you look at your dates as numbers, you will see that it's in fact a number '44042'.
Knowing that, you can use MIN together with IF formula:
=MIN(IF(B5:D5>43831,B5:D5))
Where your suggested numbers are in cells B5:D5 and '43831' is 2020/01/01.
Of course, if you have numbers with high values, this solution should be adapted.
Here's a screenshot I made:
img

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 best find the minimum positive difference of a value compared to a table efficiently using one Excell cell only?

I want to avoid VBA as much as possible and try to find a solution in a single cell--if possible. I have been trying to find a way to do so, but I have no idea how to.
The logic is summarized in the image below. In words, the conditions are:
Search Name is looked for in the Name column of the right table.
Search Date has to be greater than the Date in the right table.
Search Date minus Date has to be the positive minimum value.
Return the Pay that matches the criteria--which is 500 in the example.
You could use the following array formula (i.e. you need to enter it with Ctrl+Shift+Enter, if you are successful, you will see the braces appear in the formula bar):
=INDEX(G:G,MATCH(A2,IF(F:F=B2,E:E)))
The formula will return #N/A if there are no dates earlier than the Search Date.
NOTE: The dates have to be sorted in ascending order for this to work
EDIT: A little more robust that doesn't require sorting:
=INDEX(G:G,MATCH(MAX(IF((F:F=B2)*(E:E<A2),E:E)-A2),IF((F:F=B2)*(E:E<A2),E:E)-A2,0))
Note: Since this doesn't use MATCH, you won't get #N/A in case there are no dates earlier than the Search Date and you will instead get Pay (i.e. the header). If you want to get something else, then you can wrap the whole function in an IFERROR, relying on the fact that excel returns an error if one attempts to multiply a text with a number, something like this:
=IFERROR(Formula*1, "No pay matched")
This can be done with SumProduct, which does not require Ctrl-Shift-Enter
=SUMPRODUCT($G$2:$G$9,(A2>$E$2:$E$9)*(MONTH(A2)=MONTH($E$2:$E$9)*($F$2:$F$9=B2)))
The logic commands that the Search Date is in the same month as the Date column.
If you have the new Dynamic Array functions, that are currently in preview in the Insider Fast build of Excel 365, you can use
=FILTER($G$2:$G$9,(A2>$E$2:$E$9)*(MONTH(A2)=MONTH($E$2:$E$9)*($F$2:$F$9=B2)))

Countif criteria and range are time values, excel 2016

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!

Excel: Subtracting Dates Without Reference Cells

I want to program a cell to calculate the number of days I have left before I meet a deadline.
I would like to do this without reference cells, unlike this tutorial.
An (incorrectly formatted) example of the kind of formula I want would be:=(3/2/2015-TODAY()), where 3/2/2015 is my deadline. This yields some negative serial number,-42051.00, which yields a #NUM! error when put into the DAY formula.
Any idea how to do this without putting TODAY() and 3/2/2015 into their own reference cells? I would like to use functions to keep these paraments completely embedded in the formula.
Right clock the cell with the answer and reformat it as NUMBER. You want to use the Days function not the date function.
=DATE(2015,3,2)-TODAY() is what you want, but I would recommend doing the date in a separate cell for a number of reasons and using "today()" in the formula.
EDIT: Anyone trying to find midpoints would use the date function in this case.
Also, as a general rule for people trying to subtract dates the two trouble shooting methods you want are
A) Check your format-If you want number of dates, it needs to be set as number, if you want a date, you need it to set as date. If you get a long decimal it means you have it formatted as general OR your expression returns a date value rather than a number value. Refer to my original answer.
B) Reverse your dates. Depending on the function and what you want, you may need to move the dates around.
=DATEDIF(DATEVALUE("03/02/2015"), TODAY(), "d")

Resources