INDEX/MATCH Multiple Criteria Between Dates - excel

Hope you can help me
My expected result is in column I,
where if the activity of this specific ID falls into the date range from columns C-D, i will get the minimum date and get the name column
however, in the formula i created, it always get the minimum date for that specific ID and its corresponding name
Not sure how to update the formula, to get the outcome that i need
Appreciate any help!
Thanks
excel sample

Put the dates in a single ordered column if you can:
| A | B
1 | 2016-01-01 | able
2 | 2016-04-01 | baker
3 | 2016-07-01 | charlie
4 | 2016-10-01 | dog
5 | 2017-01-01 | easy
Then if you can use Index-Match like this:
| IN | =Match(IN1, A:A) | =Index(B:B, Match(IN1, A:A))
1 | 2016-01-01 | 1 | able
2 | 2016-02-01 | 1 | able
3 | 2016-04-01 | 2 | baker
If your date ranges have to be in two columns - there's probably a much more complicated way to do this using array formulas.

Use this Array formula:
=INDEX($E$2:$E$7,MATCH(MIN(IF(($C$2:$C$7=G2)*($D$2:$D$7<=H2),H2-$D$2:$D$7)),IF(($C$2:$C$7=G2)*($D$2:$D$7<=H2),H2-$D$2:$D$7),0))
We need to find where the date is closest but less than the criteria.
Being an Array formula it must be confirmed with Ctrl-Shift-Enter when exiting Edit mode. If done correctly Excel will put {} around the formula.

Related

Excel formul to count Table Range using month from date text

I have an excel workbook where I am trying to count the number of apples in a named table. The workbook has multle sheets each named Jan, Feb, Mar, etc. with a corresponding table range of the same name.
My main worksheet has a list of months as columns and fruit as rows, I want to use a countif or suitable function to count the number of each fruit per month using the column heading as the worksheet portion of the formula.
This is what I have tried, this works, but has to be manually coded for each month, i would prefer it be more dynamic.
=COUNTIF(JAN[Labels],$A2)
Note: A2 contains the word apple
I have tried to get the month from the column date but it doesnt work
=COUNTIF(TEXT(E25,"mmm")[Labels],$A2)
This is roughly what the "master" table should look like (for clarity)
| | Jan-20 | Feb-20 | Mar-20 | .... |
| Apple | 4 | 3 | 5 | ... |
| Pear | 5 | 4 | 9 | ... |
EDIT:
Just to assist with anyone trying to help, this is roughly what a table on another sheet will look like:
| invoice | labels|
| 12535 | Apple |
| 12536 | Pear |
| 12537 | Apple |
This table would be a named table of Jan or Feb, etc.
Please try this:-
=COUNTIF(INDIRECT(TEXT(G2,"mmm")),"A")
G2 contains a proper date.
Here is a variation of the above where column 2 of the table is specified as the range to count in.
=COUNTIF(INDEX(INDIRECT(TEXT(G2,"mmm")),0,2),"B")
If you must use column captions to identify the column I would suggest MATCH to find it.
OK, so I found an answer, combining the above answer by Variatus with an additional new row.
| A | B | C | D |
1| | Jan-20 | Feb-20 | Mar-20 |
2| |JAN[Labels]|FEB[Labels]|MAR[Labels]| <- =UPPER(TEXT(B1,"MMM"))&"[Labels]"
3|Apple | 5 | 7 | 3 | <- =COUNTIF(INDIRECT(B$2),$A3)
4|Pear | 7 | 2 | 9 |
5|Orange| 1 | 3 | 3 |
So formula in B2 makes an uppercase text value of the month from B1 plus the column name Labels.
The formula in B3 (and down) counts the number of instances of the fruit from the named table & column shown in B2.

Calculating Time Between Time/Days In Excel

I am having some difficulty finding the optimal solution to a problem I am having with Excel. Right now, I have a large sheet which has time on one axis (column A is every date between 1/1/2018 to 1/1/2019), and in the sheet I have time using the h:mm:ss function in different cells on different intervals.
For example, for rows 1/1/2018 - 1/3/18, there is a starting time on 1/1/2018 (example, 8:00:00), and then an ending time on 1/3/18 (example, 16:00:00).
The time between those two dates and two times on those dates is what I am looking to calculate.
This is on a sheet with 2000+ rows, and each interval is different (some may be three days, some may be the same day). The difference between all of these is another column with location. This looks like:
Row 2) Date, Location [A], Arrival Time (8:00:00), Departure Time (blank)
Row 3) Date (the next day), Location [A] (the same as above), Arrival time (blank), Departure Time (16:00:00)
+---+----------+----------+---------+-----------+
| | A | B | C | D |
+---+----------+----------+---------+-----------+
| 1 | Date | Location | Arrival | Departure |
| 2 | 1/1/2018 | A | 8:00 | |
| 3 | 1/2/2018 | A | | 16:00 |
| 4 | 1/3/2018 | B | 8:00 | 16:00 |
| 5 | 1/4/2018 | C | 5:00 | 13:00 |
| 6 | 1/5/2018 | C | 5:00 | 10:00 |
+---+----------+----------+---------+-----------+
I need to calculate the time spend in Location [A] between Arrival time on one date to the Departure time on the next date.
Please let me know what you think the optimal solution is to this problem, I am open to anything!
+--------+----------+---------+-----------+------------------------+
| Date | Location | Arrival | Departure | Time Spent in Location |
| 1/1/18 | A | 8:00:00 | 16:00:00 | 8:00:00 |
| 1/2/18 | B | 8:00:00 | | |
| 1/3/18 | B | | 18:00:00 | 34:00:00 |
| 1/4/18 | C | 8:00:00 | | |
| 1/5/18 | C | | | |
| 1/6/18 | C | | 16:00:00 | 56:00:00 |
+--------+----------+---------+-----------+------------------------+
The post from above is dead accurate - The trouble I am having is from the time intervals for each location being different (and random). I am trying to simply have an additional column which calculates the time spent in each location - from there I will be collecting data on each location and how many hours will be spent there.
Also, a big THANK YOU for the help so far! I am shocked by how quickly comments were made - sorry for the time it took me to make the mock-up, hope it helps make my goal in this more clear.
Actual Snip from sheet
One possible solution is to use the following formula in E2 and copy down.
=IF(C3="",((A3+D3)-(A2+C2)),IF(D3<>"",D3-C3,""))
EDIT: D4-C4 changed to D3-C3 in formula above)
It works by combining the date to the time, doing a math operation as needed and then stripping it out. Tap in a couple of IF statements to deal with rows that are single line locations, or the arrival only. It also assumes the first entry cannot be a departure.
Credit to urdearboy for the correct custom formatting. You will need to format the cells of the column to be [h]:mm
OPTION 2
This assumes that locations can be repeated. The use of a helper column is used to create a unique combination.
In F2, use the following formula and copy down as required:
=COUNTIFS($B$2:B2,B2,$C$2:C2,"<>"&"")
The $ locking the cells is very important. Note how it creates an expanding range as you copy down.
now technically speaking you can combine the following into one monster formula, but it will be difficult to follow and therefore maintain if someone else has to deal with it or you come back to it at a much later date. So on that note I will break it into 2 more helper columns and formulas
In column G we will identify the first row where a unique location occurs. A unique location is created by compounding the location name and the unique ID number which is a count of how often it has occurred in the list so far. Ie. A1 is the first time there was an arrival at location A, E2 is the second arrival at location 2. In G2 place the following formula and copy down.
=AGGREGATE(15,6,ROW($A$2:$A$16)/(B2&F2=$B$2:$B$16&$F$2:$F$16),1)
Now that the arrival row is identified the same needs to be done for the departure row. The same formula can be used but change the 15 to a 14. In H2 place the following formula:
=AGGREGATE(14,6,ROW($A$2:$A$16)/(B2&F2=$B$2:$B$16&$F$2:$F$16),1)
Now that you have those locations identified, you can use the following formula to calculate time:
=IF(D2="","",(INDEX(A:A,H2)+INDEX(D:D,H2))-(INDEX(A:A,G2)+INDEX(C:C,G2)))
In the example, I placed it in I2 and then I copied F2:I2 down as required. but it could be placed in E2 and copied down just as easily.
If you do not want those additional helper columns in G and H, then you can substitute them into your formula for time and it will look like this:
=IF(D2="","",(INDEX(A:A,AGGREGATE(14,6,ROW($A$2:$A$16)/(B2&F2=$B$2:$B$16&$F$2:$F$16),1))+INDEX(D:D,AGGREGATE(14,6,ROW($A$2:$A$16)/(B2&F2=$B$2:$B$16&$F$2:$F$16),1)))-(INDEX(A:A,AGGREGATE(15,6,ROW($A$2:$A$16)/(B2&F2=$B$2:$B$16&$F$2:$F$16),1))+INDEX(C:C,AGGREGATE(15,6,ROW($A$2:$A$16)/(B2&F2=$B$2:$B$16&$F$2:$F$16),1))))
A tidied up version using the monster formula and therefore not needing column G and H formulas:
Remember to apply custom formatting to your time calculation column of [h]:mm

Moving range/array reference in Excel table

Friends, I'm hoping you can help. I'm fairly certain I found a solution to this problem below a while ago, but silly me didn't write it down and now I can't remember how I did it. I'm drawing a blank on what to search for (Google is flooded with answers on "dynamic named ranges", which is not what I'm aiming for here). So, the question:
How can I define a range within a formula (say, RANK for example) that moves as I progress down through a table? I'm trying to avoid using INDIRECT, because it becomes a bit of a memory/processor hog when repeated throughout a large table. Pretty sure there is another way, maybe with INDEX or MATCH?
A simplified version of the data would appear as follows:
Column A has a bunch of reference numbers, each one repeats a few times.
Column B has a bunch of timestamps
Column C is where I would like to rank the timestamp in column B, as compared to all other timestamps that share the same reference number in column A.
The result set should look like this:
| A | B | C |
| abc123 | 01/01/2014 12:30 | 1 |
| abc123 | 01/02/2014 12:30 | 2 |
| abc123 | 01/02/2014 13:30 | 3 |
| abc123 | 01/03/2014 09:30 | 4 |
| def456 | 01/01/2014 12:30 | 1 |
| def456 | 01/01/2014 12:45 | 2 |
| xyz987 | 01/02/2014 12:30 | 1 |
| xyz987 | 01/02/2014 16:30 | 2 |
| xyz987 | 01/03/2014 11:30 | 3 |
Any ideas on what would be the least taxing solution for the processor in this case?
So here is the trick:
copy and paste in C1 and drag and fill down till end.
=IF(A2=A1;SUMPRODUCT(--(A$1:A$9=A1);--(B1>B$1:B$9))+1;SUMPRODUCT(--(A$1:A$9=A1);--(B1>B$1:B$9))+1)
this is an array formula, so press ctrl+shift+enter to calculate the formula
Here is the example sheet in this file downloadable from this link
P.S. remember to adjust the formula to your regional settings by replacing the ";" with "," . Have fun.

Is it possible to populate sumif with dynamic range

I have the following data in Excel Worksheet A, which is a basic ledger of expenses:
The initial data looks like:
Week | Amount | Payee | Category
1 | 10.00 | John | Cookies
1 | 12.00 | Bill | Cookies
3 | 7.08 | Jason | Oranges
...
And I have assigned categories and calculate subtotals like this on another sheet using SUMIF :
Category | Total | Include?
Cookies | 22.00 | True
Oranges | 14.87 |
...
I'm trying to get to a report that sums if that Include? boolean is set. By using SUMIF again, I can summarize by week:
Total IncludeSet?
1 100.06
2 100.3 22.00
3 80.07
4 77.29
...
I know I could create an Extra column, and I could also try a SUMIFS and apply multiple criteria, but I'm up for learning how the pros would tackle this. At some point, I should just put this into MATLAB or a database.

Average of multiple survey responses (columns)

I feel a bit embarrassed for asking this but here goes:
I'm using Excel 2010 and I have a worksheet containing 700+ customer satisfaction survey responses. Each row is a survey with a 1-5 or NA response to 5 questions. It looks like the following:
+-Agent--+--Q1--+--Q2--+--Q3--+
| | | | |
| Jeff | 5 | 5 | 5 |
+--------+------+------+------+
| James | 1 | 1 | 1 |
+--------+------+------+------+
| Jack | 5 | 5 | 5 |
+--------+------+------+------+
| Jeff | 3 | NA | 5 |
+--------+------+------+------+
| Jeff | NA | NA | 3 |
+--------+------+------+------+
| James | 5 | 5 | 5 |
+--------+------+------+------+
| ... | ... | ... | ... |
+--------+------+------+------+
I want to create a worksheet listing each agent in column A and the average of all of questions answered regarding them. I tried a formula like AVERAGEIF(SurveyResponses!A2:A7,A2,SurveyResponses!B2:D7) where A2 contains the agent's name, but it doesn't appear to work properly.
For example, I get a 5.00 average for some agents when it should be a 4.61. When I look in the Function Arguments screen for my AVERAGEIF on this person, it looks like it recognizes the values properly. The Average_rage shows {"NA","NA","NA","NA",1;5,5,5,5,5;5,... but the returned value below that says = 5 which is not right since there is a 1.
Can anyone guide me in the right direction?
AVERAGEIF works like SUMIF, the second range used is actually the same size and shape as the first range, starting with the top left cell, so when you use this
=AVERAGEIF(SurveyResponses!A2:A7,A2,SurveyResponses!B2:D7)
because the first range is a single column then the second range used must be too (there's a 1 to 1 relationship between the cells) so because the top left cell in SurveyResponses!B2:D7 is SurveyResponses!B2 the range begins there and is the same size and shape as SurveyResponses!A2:A7
....so you are actually getting this....
=AVERAGEIF(SurveyResponses!A2:A7,A2,SurveyResponses!B2:B7)
AVERAGEIF help does tell you that but it isn't very clear
If you want the ranges to be different sizes you need an "array formula" like this
=AVERAGE(IF(SurveyResponses!A2:A7=A2,SurveyResponses!B2:D7))
You need to confirm that with CTRL+SHIFT+ENTER so that curly braces appear around the formula in the formula bar. That formula will count any blanks as zeroes but ignore text values like NA
Easiest way to do this would be a pivot table. They look scary, but they're fairly easy to use. Rows = names, Columns = Q, Average for the answers.

Resources