Using a date range in an array formula - excel-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

Related

Trying to find the value of corresponding range of cells that contain dates, but only interested in the date is TODAY

So, I have a range of monthly dates that span several years. Then I have a dollar value in the next cell lets call it A1:B100. I want to find the cell in B that corresponds with today's date. What I've used that works in finding the correct date is: AND(MONTH(a1)=MONTH(TODAY()),YEAR(a1)=YEAR(TODAY())) I just need to put it in a lookup function that spans the date range, but I'm stumped
Any help would be great.
These functions look for the value in b that matches today's date and then pull in the value from a. xlookup has an easier syntax, but you may need index/match if you don't have the newest version of excel.
=INDEX(A1:A5,MATCH(TODAY(),B1:B5,0))
=XLOOKUP(TODAY(),B1:B5,A1:A5)
Edit: I re-read your post, and if your data in a is by month (ie 1/1/2021, 2/1/201), just make sure it is in order, and change the match type to less than. If your data is in a different format, please post a screenshot of your data.
=INDEX(A1:A8,MATCH(TODAY(),B1:B8,1))
=XLOOKUP(TODAY(),B1:B8,A1:A8,,-1)

Excel - Minimum and If statement - date error

I am trying to write a formula that checks the status and name to be ongoing and joe blogs (in this example), and once finding a match, will identify the oldest date of a ticket raised.
My formula currently includes:
=MIN(IF('Sheet2'!AA:AA="ONGOING",IF('Sheet2'!Q:Q="Joe Bloggs",'Sheet2'!B18:B49)))
I also tried:
=IF((AND(sheet2!$AA:$AA="ongoing", 'Sheet2'!$Q:$Q="Joe Bloggs")), MIN('Sheet2'!B18:B49),"No")
In Column B contains dates. Q contains names, AA contains the status.
At the moment when this runs I get the result '00/01/1990'.
I have done some checks to find the error, and appears to be around the targets name, as when the second formula is tried, the output is "no". The name is definitely in the Q column, and I have completed other formulas including countifs which have worked perfectly fine.
I have done a lot of searching to find nested ifs and min statements to have no joy , would be grateful of any advice / tips. It may be a simple error to some.
Try entering this as an array formula:
=MIN(IF(sheet2!AA:AA="ongoing",IF(sheet2!q:q="Joe Bloggs",sheet2!B:B)))
FYI I found the solution here.
You will have to apply a date format to the result.
Your first formula works well on my data (as below). If I close the formula with ENTER only, I get the result '37128' and if I close the formula with CTRL+SHIFT+ENTER I get the expected result, '25/08/2001'.
Edit: As #FocusWiz said in the comments, the only major difference (other than different column names) between my formula and yours is the the last range in your formula (B18:B49) is a different sized range to the other two, which are referring to full columns.
*This could be solved either by using the same row range for all three column references (AA18:AA49, Q18:Q49, B18:B49) or referencing the full column range for all three ranges (AA:AA,Q:Q,B:B).
This is your formula I'm talking about:
=MIN(IF('Sheet2'!AA:AA="ONGOING",IF('Sheet2'!Q:Q="Joe Bloggs",'Sheet2'!B18:B49)))
And this is the formula in my workbook F7:
=MIN(IF(B:B="ONGOING",IF(A:A="Joe Bloggs",C:C)))
As you can see in the formula editor, squiggly brackets '{}' show around the formula when it has been closed as an array formula.
If that doesn't work for you, please post some sample data with datatypes so we can help figure out what is causing the lookup value to miss the data.
While I like the technique offered by Patrick (I have frequently forgotten an "else" portion of a formula and gotten "false" as a value in a cell but never thought of a use for that...thank you!), I think this question highlights an issue we all can have with array formulas. As girlvsdata indicates, your original formula:
=MIN(IF(Sheet2!AA:AA="ONGOING",IF(Sheet2!Q:Q="Joe Bloggs",Sheet2!B:B)))
(modified above to be more generic for column B) will also work when entered as an array formula.
What likely happened is that somehow the formula got edited and was not re-entered as an array formula.
While I do not dislike array formulas, I do try to avoid them because I have fat fingers and will frequently mess them up by accidentally hitting the wrong key as I am modifying other cells.
Here is an alternative without using an array formula:
=INDEX(LARGE((Sheet2!Q:Q&Sheet2!AA:AA="Joe bloggs"&"ongoing")*(Sheet2!B:B),COUNTIFS(Sheet2!Q:Q,"Joe Bloggs",Sheet2!AA:AA,"ongoing")),1)
What it does is basically create a candidate date value for every row that has "joe bloggs" and "ongoing" which is equal to the date in column B for all such rows. All other rows get a zero candidate date value. The LARGE function takes the smallest nonzero date by counting the n valid candidates with the COUNTIFS function and taking the nth largest such candidate.

Excel SUMIF Function with Multiple Criteria for One Range (not SUMIFS)

UPDATE 2
Here is my formula and the resulting error. There are "#DIV/0" results in column J in some of the March data.
END OF UPDATE 2
UPDATE
So as you can, I am trying to sum up column J for each month (those totals will go in column R-W). So I need to the SUMIF function to look at data that begins with a certain date, which I was able to figure out, but also to not include anything in the sum that is an error.
END OF UPDATE
I've looked around for a bit for an answer to this question but what I am finding is people are using SUMIF when they are looking at two different ranges; not what I'm trying to do.
I am trying to do a SUMIFS that looks at ONE range and has multiple criteria.
For example, I have 262,025 rows in this file. I am trying to write a function that does a summation only if the date begins with 2016/03. The problem is, the data I am actually summing contains some "#DIV/0" errors in it.
This is what I was thinking:
SUMIF(E6:E262025, AND("2016/03*", <>"#DIV/0", J6:J262025)
This does not work though.
Basically, I want to sum up column J only if the month is March and I want to exclude any of the values in column J that are "#DIV/0". If this is indeed a SUMIFS function then my apologies. I looked at the syntax for that function and I didn't think that was what I needed. Looking forward to some feedback.
A simple SUMIFS will do:
=SUMIFS(J:J,E:E,"<=3/31/2016",E:E,">=3/1/2016")
It will ignore the errors.
EDIT
Now that you posted a picture it is obvious that your dates are not actually dates but text that look like dates. Then you can use this simple SUMIF:
=SUMIF(E:E,"2016/3*",J:J)
Again it will ignore the error.
Edit #2
If the errors are in the value column then we will need to use an array formula that ignores them:
=SUM(IF(ISNUMBER(SEARCH("2016/03",E6:E262025))*(ISNUMBER(J6:J262025)),J6:J262025))
Being an array formula it must be confirmed with Ctrl-Shift-Enter upon exiting Edit Mode instead of Enter. If done correctly then Excel will put {} around the formula.

Lookup Job Code, return column header if cell has text

I'm looking for a little bit of help learning about how to use vlookup and iferror formulas together.
I am working as a licensing specialist within the insurance industry. My job requires that I frequently access more than a dozen spreadsheets that are emailed to us on a weekly basis from our clients. I am working to develop tools that allow us to consolidate that information on-demand to be able to run reports. I'm having no trouble using the VLookup function to pull data from various spreadsheets using an unique identifier. I do need some help, however, with a trickier formula.
I have put together a spreadsheet that allows me to put in the ID of the representative and it returns various bits of information, such as their name, license numbers, job codes, etc. Now I need to come up with a formula that takes the value returned in the job code field and searches another spreadsheet to return what training they are required to complete based on their job code. This spreadsheet is about 2000 rows, and is formatted with the training names spanning across the top row, job codes listed in column "A" and the word "yes" in each column that matches a training that the job code is required to take.
It looks like this: https://i.imgur.com/71COmfF.png
I need the formula in my reports spreadsheet to lookup the job code using VLookup and then return the column header if the cell has text.
The data will be loaded into this spreadsheet: https://i.imgur.com/2CyFURt.png
Here is the Vlookup formula I am using to get the job code:
=VLOOKUP(B3,'.\[Weekly_HR_Report_040615.xlsx]HR'!$A:$Q,10,FALSE)
How can I pair that same kind of formula with something like an IfError formula to return the column header if there is a "Yes" in the cell of the row that matches their job code?
I know that I can work through it as an array using VBA, but I would prefer to just place a formula in each cell so that I can pass this spreadsheet to another college when I move to a different role in the future and they won't struggle too much with adding to it.
Thanks for any help that you might be able to provide! I really appreciate it!
I would use INDEX and MATCH to cross reference and retrieve the titles where applicable:
=IF(INDEX('JobCode_Training.xlsx'!$A$1:$H$6,MATCH($H$5,'JobCode_Training.xlsx'!$A:$A,0),2)="Yes",INDEX('JobCode_Training.xlsx'!$A$1:$H$6,1,2),"")
=IF(INDEX('JobCode_Training.xlsx'!$A$1:$H$6,MATCH($H$5,'JobCode_Training.xlsx'!$A:$A,0),3)="Yes",INDEX('JobCode_Training.xlsx'!$A$1:$H$6,1,3),"")
=IF(INDEX('JobCode_Training.xlsx'!$A$1:$H$6,MATCH($H$5,'JobCode_Training.xlsx'!$A:$A,0),4)="Yes",INDEX('JobCode_Training.xlsx'!$A$1:$H$6,1,4),"")
etc.
I wasn't sure what your reference table is saved as, so you'll need to replace 'JobCode_Training.xlsx'! with whatever the correct path is.
Since you have multiple trainings that can apply to each jobcode, you'll either need to have multiple cells for the results, or you can concatenate them into one.
The following article from excelvlookuphelp.com answers your question I believe...
The Problem
You might be expecting that not all of your search values are going to return something from the search table. Instead of the formula returning #N/A you’d like the result to look different when your vlookup value isn’t found (either blank or an indicator to show that the value hasn’t been found or a zero if you’re wanting to do maths with the results).
The Solution
You can use the iferror function.
It works like this
= iferror (YourVlookupFormula, WhatToSayInsteadOf#N/A)
Here’s an example
=iferror(vlookup(D3,A:C,3,false), “No Value Found”)
Or if you would rather it was just blank then instead of having No Value Found, just have the two sets of inverted commas, like this
=iferror(vlookup(D3,A:C,3,false), “”)
source: excelvlookuphelp

SumIf using dates and ranges in VBA

I am trying to sum a row biased on the fact that another row has the same month as a variable that is defined by the user. I believe the sumif function would be my best bet but it doesn't seem to be working for me. The row I want it to look at obviously is a row of Date with date formatting (used .numberformat = "ddd mm/dd") but the sumif doesn't seem to be able to pick out the month in each cell. Here is the code I have so far:
Dim cMade As Integer
Dim sDate As Date
cMade = cMade + Application.WorksheetFunction.SumIf(ActiveSheet.Range("B1:RC1"), Month(sDate), ActiveSheet.Range("B30:RC30"))
As you can see sDate is the date that the user imputs via userform then i convert that using dateserial. and B1-RC1 are the dates i want it to look at. And Range B30-RC30 are the sums i want it to grab if the months match up (the reason I have it as + cMade is because it is in a loop that loops through sheets).
Is this code correct? I have been messing with it and looking for alternatives for hours but I cant not seem to come up with anything!
Assuming this is only a part of your code and I may only guess the rest, try the following corrections:
I think you should define Range("B30,RC30") as Range("B30:RC30") - comma here looks like a typo according to the description.
Replace Application.SumIf with Application.WorksheetFunction.SumIf.
As an addition, consider to define ranges more precise, e.g. via Worksheets("Sheet1").Range("A1:C10") or ActiveSheet.Range("A1:C10") syntax. However, this may be an extra measure - I don't see the rest of your code.
Hope that was somehow helpful.

Resources