Countifs formula: count if matches month, year and another criteria - excel

I'm sure this is quite a simple formula to some, however I'm struggling to get this right.
The data I have is:
A C D
Location 1 Name 10/10/2019
Location 2 Name 01/10/2019
Location 1 Name 10/08/2020
Location 1 Name 12/10/2019
. . .
I am trying to count how many are in a location in each month of the year. (Eg above the count for Location 1 in Oct 19 is 2)
I have managed to get some aspects working, but I cannot get it working together.
eg, this works: =COUNTIFS('sheet1'!D5:D298,">"&30/10/2020)
works however =COUNTIFS('sheet1'!D5:D298,"<"&30/10/2020) does not.
I also cannot get it working with the multiple criteria. ( =COUNTIFS('Counter Balance'!D5:D298,">"&30/10/2020, 'Counter Balance'!A5:A110, "Location 1")
I'm clearly doing something obvious wrong but I just can't see it!
Hopefully that makes sense, any advice would be much appreciate,
thank you!

=COUNTIFS($A$2:$A$5,A9,$C$2:$C$5,">="&DATE(C9,B9,1),$C$2:$C$5,"<"&DATE(C9,B9+1,1))
qty results to 2, as you may expect

The COUNTIFS function needs to have a bit of uniformity in the formula to work.
Microsoft references it here:
Important: Each additional range must have the same number of rows and columns as the criteria_range1 argument. The ranges do not have to be adjacent to each other.
While not necessary, I would recommend using DATE functions, cell references, named ranges, or some other form of control for comparing dates in formulas. Excel treats a date as an integer internally. Combine that with differences in language localization and its pretty easy for the dates in date format to not mean what you want them to mean.
To try to correct your formula, I would recommend this:
=COUNTIFS('Counter Balance'!D5:D298,">"&DATE(2020,10,30), 'Counter Balance'!A5:A298, "Location 1")

Related

Use VLOOKUP as criteria inside COUNTIFS

After years of using this community, I have a question that I can't find an answer to. I hope you all can help!
I am trying to get a count of the number of "Grounded" items that each individual is overdue for. My screenshot (Count Tracker) shows a very condensed version of what I'm working with. Columns A-C is my large (15,000 rows) data field that is imported from an external source. In columns G-H I have listed each possible task (about 100 rows) and the type (Grounded and Non-Grounding plus many others). Column F is where I am trying to get the count.
My formula in F9 currently uses COUNTIFS to get a count of the instances in the large array that equal E9 ("Smith" in this case) and where the due date in the large array is less than or equal to the current date in F8. What I can't figure out is how to also add to count the Tasks in the large array where the task type in Column H equals "Grounded". I tried VLOOKUP, but it seems it doesn't like it and tells me there is a problem with the formula. It doesn't work, but here's the general idea of what I'm after:
=COUNTIFS($A$2:$A$7,$E9,$C$2:$C$7,"<="&$F$8,VLOOKUP($B$2:$B$7,$G$2:$H$4,2,FALSE),"=Grounded")
With how the data is currently presented, Smith should have a count of 1 and Jones should have a count of 0. I have a feeling that this is more simple than I'm making it to be, but I can't figure it out. I am using Excel 2016.
Hopefully I explained the problem well enough. Thank you for your assistance.
With Excel 2016 I'd say MMULT() is a good alternative here:
CSE-Formula in F9:
=SUM((A$2:A$7=E9)*(MMULT((TRANSPOSE(G$2:G$4)=B$2:B$7)*(TRANSPOSE(H$2:H$4)="Grounding"),ROW(G$2:G$4)^0))*(C$2:C$7<=F$8))
You could add a fourth column that stores whether that Task is Grounded
The formula for D2 would then be:
=INDEX($H$2:$H$4,MATCH(B2,$G$2:$G$4,0))
Modify your CountIfs formula to use this new column as a criteria
=COUNTIFS($A$2:$A$7,$E9,$C$2:$C$7,"<="&$F$8,$D$2:$D$7, "Grounded")
Try this Sumproduct+Vlookup formula without helper solution, and can work for your Excel 2016
In F9, formula copied down :
=SUMPRODUCT((A$2:A$7=E9)*(VLOOKUP(T(IF({1},$B$2:$B$7)),G$2:H$4,2,0)="Grounded")*($C$2:$C$7<=$F$8))

Using a date range in an array formula

I've got a data-set, for example purposes it's a list of people (who may appear more than once) with various fields.
I need to return every match and I've done this with an array formula.
My data looks like this from Column A to F with the look up result shown in Column F. (I've simplified it for sample purposes):
and the data updates perfectly when i update the name in cell F1
This is my formula
{=IFERROR(INDEX($C$2:$C$27, SMALL(IF(COUNTIF(F$1,$A$2:$A$27), ROW($C$2:$C$27)-1,""), ROW()-1)),"")}
However I need to also to include the date in the criteria, specifically I want to be able to provide a date range, and then only return matches that are within that date range.
I've found many examples of having multiple matches in the criteria (using more than 1 countif and multiplying the results together) but nothing that will allow me to specify a date range.
I don't want to use VBA for this, hoping someone out there can assist.
always the case.
After posting that query, I managed to work it out myself.
I just changed my formula to :
{=IFERROR(INDEX($C$2:$C$27, SMALL(IF(COUNTIF(F$1,$A$2:$A$27)*($G$1>=$B$2:$B$27), ROW($C$2:$C$27)-1,""), ROW()-1)),"")}
(where G1 had a date in it) i also added a <= statement in there as well to give it a start and end date
sorry for wasting the time of anyone who looked into this for me

Using COUNTIF but not including blanks with other formula

Firstly, apologies if this is covered somewhere deep within the site, I have looked through a lot of other posts and none of the solutions have worked for me.
I'm creating a workbook for a local league I'm involved in and this is the only sticking point I'm coming up against.
In cell J55, I have the formula:
=IF(C11=H55, COUNTIF(D11, "="&E11),0)+IF(C19=H55, COUNTIF(D19, "="&E19),0)
(I've simplified this to only look at rows 11 & 19 for the purposes of this question)
So what I'm essentially saying is if the team name is equal to the corresponding name in the table, count if the scores for both teams are equal. Basically I'm trying to get the number of games that end in a draw.
So at it's core, my formula is looking for whether 2 cells are equal. This is fine, other than it is counting even if the score cells are blank.
So if you refer to the below image, in J55, I'm getting the returned value of "2". However for the values I've populated in the results (just the scores in the first game) it should be returning a value of "1".
If anybody can help in any way it would be a great help.
To count the number of Draws this formula which performs array like calculations will count the number of occurences where where the team name in H55 is equal to the team name in column D or F and when the scores in column D and E are equal:
=SUMPRODUCT((($C$11:$C$21=H55)+($F$11:$F$21=H55))*($D$11:$D$21=$E$11:$E$21)*($D$11:$D$21<>"")*($E$11:$E$21<>""))
Copy down as required.
COUNTIFS options
Based on your formula above, adding the checking for not blank cells using COUNTIFS.
=IF(C11=H55, COUNTIFS(D11, "="&E11,D11,"<>"&""),0)+IF(C19=H55, COUNTIFS(D19, "="&E19,D19,"<>"&""),0)
COUNTIFS is probably the slightly better option as it does not use array calculations. However for a small data set it wont make a noticeable difference in calculation time for most users.

Excel Formula to Count Values between Dates

I am looking for a way to count how many companies are in Column C on the specific dates of column A. Can one formula be applied to the count between all of dates?
I have tried looking up and using =CountBlanks and I do not want to have to manually select the cell ranges between the dates.
Ultimately I am also trying to put this data into a table so I can see on Feb 16 = 3 Companies, Feb 19 = 5. I can not use a VBA script as some users have macros blocked.
Please look at image for example
Example Image
Try this formula:
=COUNTA(INDEX($C$2:$C$21,MATCH($E2,$A$2:$A$21,0)):INDEX($C$2:$C$21,MIN(IFERROR(MATCH(TRUE,INDEX($A$2:$A$21>$E2,0),0),9999999),MATCH(TRUE,INDEX($C$2:$C$21="",0),0))-1))
Change the 21s in the formula to at least the extent of your data +1, It can be more, Full column references will not work due to the Word "Date" in the first row.
DATEDIF( start_date, end_date, interval )
you didnt even bother to google this, right?
edit: there should be enough common place stuff like isblank to accommodate the lack of values. If youre trying to find the values between A & C then you can easily adjust your formula accordingly.

Find a cell (using VLookup) and use the cell location found in a range

I have simple data, with one column a daily incrementing date column, and the second column being a numeric value. I want to VLOOKUP the data for todays date (which I can do) and then get the average of this value plus the 7 days values before then as well.
Something a bit like:
=AVERAGE( VLOOKUP(today(),A2:B110,2,false)) : (VLOOKUP(today()-7,A2:B110,2,false))
But with the VLOOKUP returning the cell location rather than the data.
As with so many questions on here, I have searched, but I don't know the terms I am looking for and googling anything with VLOOKUP in the terms opens floodgates to questions that aren't quite what I'm asking. Many thanks!
Sounds like your dates are in strictly increasing order, correct? In which case, assuming you're using Excel 2007 or later, you could use:
=AVERAGEIFS(B2:B110,A2:A110,"<="&TODAY(),A2:A110,">="&TODAY()-7)
This INDEX formula will also work, though is not as efficient:
=AVERAGE(INDEX(B2:B110,MATCH(TODAY(),A2:A110,0)):INDEX(B2:B110,MATCH(TODAY(),A2:A110,0)-7))
Regards

Resources