COUNTIFS not producing expected result

Using Numbers 3.6.2

Using 'COUNTIFS' to quantify Rows that feature multiple cells that meet relative criteria

Macbook Pro Retina mid 2012, El Capitan 10.11.5


I have a multi-column, ~800 Row dataset.

I can't show the actual example here to preserve the privacy of the users listed

Because time is limited I'll create a fake version of this data set only if it becomes obviously necessary to convey the problem and get a solution.


I'm trying to display particular information in extra columns added on the right side of the table, so the table can be sorted by these results later.

Here's the criteria:

IF Cell-R114 = TRUE, then;

  • TRUE
    • COUNTIFS:
      • the number of rows that feature the-ID-number-listed-in-Cell-G114, AND
      • that display a date (written at the start of the string in respective Cell in Column J) < (date-referenced-from-another-table)
  • FALSE
    • " "


Here's my current best formula. It returns '0' even though I've manually counted at least one Row featuring data that should return '5'.


IF(R136=TRUE,COUNTIFS(lastlogin,DATEVALUE(LEFT($lastlogin slane,10))<DATE(Table 2::$B$2,Table 2::$C$2,Table 2::$D$2),vssid,vssid slane)," ")

User uploaded file


Any suggestions as to why my formula isn't working?

MacBook Pro (Retina, Mid 2012), OS X Yosemite (10.10.5), null

Posted on May 26, 2016 4:11 PM

Reply
7 replies

May 27, 2016 12:53 AM in response to MrHuman

It's difficult to interpret the formula without seeing the parts of the table referenced. The highlighting of cells in the large table does not appear to match the highlighting in the formula.

User uploaded file


Syntax for COUNTIFS:


COUNTIFS(test-values, condition, test-values…, condition…)


COUNTIFS is generally placed in a single cell if it is doing a count of items fitting a single set of conditions.

It is filled down a column if counts of several similar sets are being done. in this case, for example if you were doing counts for five different vssid codes, you might list the codes in five rows of a single column and use a relative reference to the cell in that column on the same row as the formula as the condition for one of the test-values, condition pairs. The formula would then be entered into the row containing the first code, then filled down four rows to create one copy referencing each of the codes.


Your formula has two test-values, condition pairs:

  1. vssid, vssid lbleakly2
  2. T, T114 < DATE(Table 2::$B$@,Table 2::$C$2, Table 2::$D$2)


See the comments above regarding the first pair.

The second pair has a couple of errors.

COUNTIFS looks at each of the test-values in column T and compares that value with the value constructed by DATE from the contents of cells B2,C2 and D2 on Table 2. The reference to cell T114 is not needed and should be removed.

The expression of the condition must be presented as text, but within that text, numbers needs to see any cell references as cell references, not as a text string. That' a tough concept to catch on to if you're not making frequent use of it, so it's not surprising when errors occur.

The values in column T must be Date&Time values, not text. If the alignment setting on that column is Automatic, Numbers will align numbers and number-like values (including Date&Time values) to the right edge of the cell, and will align text values to the left. The left alignment of values in column T means either you have set the alignment to Left, or the values in those cells are text, not dates, and cannot be compared with the Date&Time value constructed by the Date function.


Corrected version of this pair: T, "<"&DATE(Table 2::$B$@,Table 2::$C$2, Table 2::$D$2)


Here's an example using separate tables to record the data (Table 1), do the counts (Table 2) and construct the threshold date (Table 3)

Formula list below.

User uploaded file

Table 1: Data only. no formulas.

Table 2: Two formulas


A2: =Table 3::A2

Copies the date from Table 3.


C2: =COUNTIFS(Table 1::$A,B,Table 1::$B,"<"&A$2)

Does the count.

Fill down to C5


Table 3: =DATE(A3,A4,A5)

Constructs the Date&Time value.

(Same as your formula, modified for a vertical list of yyyy, m, d)


Regards,

Barry

May 26, 2016 8:13 PM in response to Barry

Thanks for pointing that out Barry. I had indeed missed SG's f/u post.


Here's where I'm at:

- I'm breaking the formula into seperate operations

- Instead of using the Numbers function to interpret the date at the start of the respective strings, I've created a seperate column for that

- I've modified the formula but I'm still getting 0's where I should definitely be getting quantities of 1 or more.


Here's a screenshot showing the new formula and more of the table in question. I've also laid over the top the 'Date Table' where the comparative date is drawn from.

User uploaded file

There are multiple instances where the 'vssid' value occurs in multiple rows where the date is older than the date specified in the 'Threshold date' table.


Why isn't this working?

May 26, 2016 6:32 PM in response to MrHuman

Oops, I meant to type COUNTIFS. I hope I didn't add to confusion😟.


I assume you are counting things, not trying to add things up? The two work in similar ways, with column-condition pairs. With SUMIFS (unlike what I wrote) you need to start with a reference to the column you are summing, followed by column-condition pairs. With COUNTIF you don't have that initial column because you aren't summing anything. If you haven't seen it yet you can read about COUNTIFS here (you can also get there via Help > Formulas and Functions Help in your menu. Explanations in many different languages are available there.


In general I recommend keeping the structure of the formula simple. If you can post a screenshot with more of your table(s) showing what you are trying to do, lots of experts here can help you out.


SG

May 26, 2016 4:47 PM in response to MrHuman

Crucial details are missing from your screenshot, such as the setup of your columns in the table(s).


However, it does seem as if your formula is too complicated. COUNTIFS typically simply contains a series of column-condition pairs.


=SUMIFS(<a column of values>,<a condition to match them on>,<another column of values>,<a condition to match those on> .....)


SG

May 26, 2016 7:07 PM in response to MrHuman

"I can't use SUMIFS because the data in those columns is not a (plain) number, date or duration... Hmmm."


I don't think you want to use SUMIFS in any case. You're attempting to COUNT all instances where all conditions report TRUE, not to total the values in a particular column when all conditions are report TRUE.


SG noted that he'd had a wetware glitch (aka a typo) and wrote SUMIFS in the formula where he meant to write COUNTIFS. Substitute that function for SUMIFS in your formula, and see if that's the only correction you need.


Regards,

Barry

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

COUNTIFS not producing expected result

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.