Not sure if I've worded the question correctly... but, I have a spreadsheet that imports data across with a 'transaction date' and on day 1 there may be 15 transactions, day 2 there may be 30 etc.
Now I already have a formula that is counting how MANY are imported each day
=SUMPRODUCT((MONTH('Further Evidence'!$A$2:$A$5000)=MONTH(DATEVALUE(Configuration!H2&" 1")))*('Further Evidence'!$A$2:$A$5000<>""))
That shows how many have come in that particular month, what I need to work out now is what the highest intake was during that month (and if possible, which day it was).
Rather than list 365 days of the year and doing a countif in every cell next to them, is there an intuitive way to only count values that exist in the list?
It will be simple for one of you, but I can't quite figure it out or what to google :)
edit -
=MAX(FREQUENCY('New Appeals'!A2:A5000,MONTH('New Appeals'!A2:A5000)))
This works for the whole list of dates, but how can I make it check months specifically, or pinpoint the specific day?
To find the max value within a given month you can use an array formula like below
I've used a sample range of rows 36 to 48. I've assumed that date is in column I and that transactions is in column J
=MAX(IF(TEXT($I$36:$I$48, "mmm")="jan", $J$36:$J$48, ""))
(To enter an array formula you have to press ctrl + shift + enter when you are in the cell)
This is restricting the MAX function to the month of jan.
You can then find the day associated to this max value by using another array formula that is a mix of first MATCH then INDEX. The MATCH first looks for the max value within the range of cells associated to the given month, then returns this position. This position is then used in the INDEX to return the date
=INDEX($I$36:$I$48, MATCH(K34, IF(TEXT($I$36:$I$48, "mmm")="jan", $J$36:$J$48, "")))
Please note that if you have two days within a month with the same max then it will just bring back the first one
Hope this helps
Related
I have a table in which one row contains dates, another row contains AHT (Avg Handle Time) and the third row contains no of calls handled.
I have situation where I need to find the Weighted average for each week in another table. I am able to find simple average for each week. However not getting this weighted average for each week.
Thanks
This should work in most versions of Excel
=SUMPRODUCT(INDEX($3:$3,MATCH("Week "&A9,$1:$1,0)):INDEX($3:$3,MATCH("Week "&A9,$1:$1,0)+6),
INDEX($5:$5,MATCH("Week "&A9,$1:$1,0)):INDEX($5:$5,MATCH("Week "&A9,$1:$1,0)+6))
/SUM(INDEX($3:$3,MATCH("Week "&A9,$1:$1,0)):INDEX($3:$3,MATCH("Week "&A9,$1:$1,0)+6))
May need to be array-entered pre Excel 365.
Notes
The weighted mean formula is
Weighted mean = Σwx/Σw
where are the weights and x are the values. So in this case, from OP's comment, the third row is the weights (number of calls) and the last row is the values (AHT).
The easiest way to get Σwx is to use Sumproduct, and to get Σw is just to use Sum. So the basic formula for (say) week 40 would be simply
=SUMPRODUCT(A3:G3,A5:G5)/SUM(A3:G3)
However, I reasoned that it would be inconvenient to re-write this formula for each different week, so I have used Match to find the starting column of each week from row 1 , then index to find the corresponding position in either row 3 or 5 (let's call it startpos), then index again to find the position six places to the right of startpos (let's call it endpos). The required range to be placed in each part of the short formula above is therefore startpos:endpos (I can use this notation because startpos and endpos, the values returned from the Index function, are both references).
If Excel 365 is available, this can all be expressed much more succinctly and clearly using Let to assign variables names to each part of the formula.
=LET(startCol,MATCH("Week "&A9,$1:$1,0),
startWeight,INDEX($3:$3,startCol),
endWeight,INDEX($3:$3,startCol+6),
startValue,INDEX($5:$5,startCol),
endValue,INDEX($5:$5,startCol+6),
weightRange,startWeight:endWeight,
valueRange,startValue:endValue,
SUMPRODUCT(weightRange,valueRange)/SUM(weightRange))
I would like assistance in calculating the difference of date and time between each of cells 1 through 15 in hours and minutes.
The problem is the ref is not the same for all so, when the ref changes from R001 to R002, the formula should start calculating the date time difference from the first cell, with the new reference to the last cell with the same ref.
This solution will use AGGREGATE, INDEX and optionally MINUTE functions built into excel
Step 1
Build a list of unique ref IDs and place them in column D
Step 2
Use AGGREGATE to determine the LAST row that a ref ID occurs in.
AGGREGATE(16,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1)
AGGREGATE is a function that performs array like calculations. As such avoid using full column references within the function.
16 tells AGGREGATE to use the LARGE formula, so it will built a list in Descending order.
6 tells AGGREGATE to ignore/exclude any results in the list that are an error.
ROW() is going to pull the row number that is being evalutated.
-- will turn the resulting TRUE or FALSE result into 1 or 0.
C2:C16=D2 is looking to to see if the row has the REF ID .
1 tells AGGREGATE to return the 1st number in the list.
Step 3
Rinse, wash, repeat. Determine the FIRST row that a ref ID occurs in.
Again use aggregate just as before. Except this time instead of LARGE, we want to find SMALL so change the 16 to a 15. This will return the row number of the first occurrence of the REF ID.
AGGREGATE(15,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1)
Step 4
Now that you know the ROW# to use, place the row number in an INDEX formula to get the cell you want to use. Note that index actually returns the cell address so can be used just like a cell reference.
First Time Refence
INDEX(B:B,AGGREGATE(16,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1))
Last Time Reference
INDEX(B:B,AGGREGATE(15,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1))
Step 5
Take the difference between the Last and First
INDEX(B:B,AGGREGATE(15,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1))-INDEX(B:B,AGGREGATE(16,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1))
Now if the first reference occurs before the time stamp of the last referenec you will wind up with a negative number. IF YOU DO NOT CARE ABOUT THE NEGATIVE NUMBER, wrap the whole thing in an absolute function or square the results then square root the results.
ABS(INDEX(B:B,AGGREGATE(15,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1))-INDEX(B:B,AGGREGATE(16,6,ROW($A$2:$A$16)/--($C$2:$C$16=D2),1)))
Place your choice of the above formula in E2 and copy down as required.
Step 6
Since you want your answer in JUST hours and minutes, I opted to break the information into two separate columns so you could use them as needed. Also I will be referencing the values in column E instead of embedding them into the following formulas which is also an option if you want to avoid extra columns.
If you format the results in E2 as general you will note you get an integer and some decimal values. The integer represents the number of days. The decimals represent TIME as fraction of a day. In order to get the number of hours, you multiply by 24, since there are 24 hours in a day, and take just the integer. Place the following formula in F2 and copy down.
INT(24*E2)
Since you also want the minutes we can pull those directly from E2 using the MINUTE function. Place the following in G2 and copy down.
MINUTE(E2)
I have created a schedule where I am trying to lookup the value of rent for a period of time based on a given date (located in cell B1).
For example, I have the following data set:
Rent Change Date is the date when the rent increases for a specified tenant
Amount is the amount it increases to on the specified Rent Change Date
The schedule off to the right is the monthly rent schedule as dictated by the Rent Change Date
I am currently using a VLOOKUP to identify the range for each tenant using TRUE (or approximate match) to find the rent for the current month (as dictated by the date in B1).
Sample (located in cell G5):
=VLOOKUP(G4, C5:D10, 2, TRUE).
For each tenant, I then reset the table_array range. This works well for a small data set, but I have been searching for a way to set the range automatically. Is there an efficient way to get all of the Rent Change Dates by tenant? Maybe an Excel array formula?
So I'm still not 100% sure I understand what you're looking for, but here is what I came up with.
Using this formula in cell G5 (committing it with Ctrl + Shift + Enter as it's an array formula), and then copying the formula to all other cells in the G5:R7 range, you should get what you're looking for.
Array Formula:
=IF(AND(G$4>=MIN(IF((--($A$5:$A$19=$F5))=0,2,1)*($C$5:$C$19)),G$4<=EOMONTH(MAX(($A$5:$A$19=$F5)*($C$5:$C$19)),11)),INDEX($D$5:$D$19,MATCH($F5&G$4,$A$5:$A$19&$C$5:$C$19,1),1),0)
Example Results:
Result when a tenant is commencing during the year
Result when a tenant is occupied for the whole year
Result when a tenant is expiring during the year
Explanation:
There's a lot going on with this formula, and it's possible there's a simpler way, but I'll do my best to explain. After all, learning isn't just about getting an answer, but also an explanation.
Essentially what you're looking at is a large logical IF function (with three arguments: logical_test, [value_if_true], [value_if_false]). To understand its arguments better, let's break them down:
logical_test
AND(G$4>=MIN(IF((--($A$5:$A$19=$F5))=0,2,1)*($C$5:$C$19)),G$4<=EOMONTH(MAX(($A$5:$A$19=$F5)*($C$5:$C$19)),11))
I started with the AND function because I am attempting to find if a given date (G$4) is either the same as or greater than the first Rent Change Date for a Tenant (this is found using the MIN function) and if the same given date (G$4) is either the same as or less than the end of the month (EOMONTH function) 11 months in the future from the last Rent Change Date for a Tenant.
The embedded IF function within the MIN function is simply there to ensure the correct minimum date is returned. Removing this logical causes the minimum to return 0, which is incorrect for our needs.
I used the EOMONTH function due to the assumption that when the rent changes - including the final rent change - it lasts for a year. Failing to add this piece to the formula would end the rent the same month as the Rent Change Date.
If both statements within the AND function return TRUE, the logical_test then proceeds to the [value_if_true] argument.
[value_if_true]
INDEX($D$5:$D$19,MATCH($F5&G$4,$A$5:$A$19&$C$5:$C$19,1),1)
INDEX(array, row_num, [column_num])
MATCH(lookup_value, lookup_array, [match_type])
COMBINED:
INDEX(array, MATCH(lookup_value, lookup_array, [match_type]), [column_num])
Using the INDEX and MATCH functions together is allowing us to look at the data from any angle without having constraints placed on us. In this case, our array argument - $D$5:$D$19 - spans the entire area of our Amount column. This is where we want to return our value from, so it's important that we cover the full area.
In the place of row_num we use the MATCH function. In our table spanning F4:S8 (which includes the column and row names) we are given both the tenant name ($F5) as well as a reference date (G$4). Combining these with an ampersand (&), we now have a concatenated lookup_value for MATCH. By concatenating these two together, we are increasing the likelihood that our lookup_value is unique and will return us the required information.
If two tenants happen to have the same Rent Change Dates but different names OR if two tenants happen to have the same name but different Rent Change Dates, we will get a unique match; in the rare instance that two tenants share the same name and Rent Change Dates, one tenant will need to have something different to stand out, such as a unit number in the name
Now that we have our lookup_value for MATCH, we need to supply a lookup_array. Given that our lookup_value is a combination of the tenant name ($F5) and a reference date (G$4), we set our lookup_array for MATCH to be a concatenation of $A$5:$A$19 (spans the entire area of our Tenant column) and $C$5:$C$19 (spans the entire area of our Rent Change Date column), joined together with an ampersand (&).
The last argument our MATCH function needs is the [match_type]. For this formula I chose 1 - Less than (Finds the largest value that is less than or equal to lookup_value. The values in the lookup_array argument must be placed in ascending order) due to the fact that we are looking for a date that is either the date itself or one that is less than it as well as the fact that our dates are in ascending order for each Tenant. If we instead looked for an exact match ([match_type] set to 0 - Exact match), we would receive a lot of errors since the Rent Change Dates increase annually, not monthly (like our reference dates in G4:R4). Similarly, looking for a greater than match ([match_type] set to -1 - Greater than) also returns a lot of errors, primarily because the dates aren't in the required descending order.
Closing out of the MATCH function with a ), we return to the [column_num] of the INDEX function from earlier. While this argument is optional with a one-column array, I entered a 1 for clarity. All this means is that once the MATCH function determines which row to grab, I want to get the intersection of [row_num] (which is 1 in the case of G5 using the presented formula along with 2/1/2018 as the date in B1) and [column_num] (1) from the array (the Amount column, $D$5:$D$19). Row 1, Column 1 from the array is $150.00, which is exactly the expected result.
The last piece of our formula is to finish off the IF statement we started with, entering a value for the [value_if_false] argument.
[value_if_false]
0
In the case of this IF function, we simply entered 0 for the [value_if_false] argument. I chose 0 because if the tenant hasn't yet commenced or has expired, we want to reflect a total rent of $0.00 for a given month.
Hopefully this all makes sense and is what you're looking for.
If you create a pivot table based on your data table it can automatically put all the dates across the top row (and you can group by quarter, months, years, days if you so desire).
If you want to search for months, but only have rent rates for years in your source data you may need to use sumproduct. (A pivot table will only include dates where they exist in the source data that I'm aware of, it won't add all dates covered by a range unless explicitly included in that range)
It would like something like below;
=Sumproduct($c$5:$c$300,--($a$5:$a$300=$a2),--($b5:$b$300>b$1),--($b5:$b$300<c$1))
Assumption here is the grid showing data across the top starts from cell a1, and the source data starts from a5.
Because sumproduct effectively is an array formula (you don't need to use Ctrl + shift + enter, it just behaves the same way as an array formula) it's generally not recommended to apply it to a full column for performance reasons.
I have two columns of dates. One is the move in date and the other the move out date. I want to figure out how many days the tenant was there during a second date range. for example: how many total "bed days" did we have in the month of July? 7/1/2016-7/31/2016
This function calculates the number of days each tenant was there each month but I would like it if I could get the entire calculation into one cell without creating a dummy column for each month.
=MAX(0,MIN(EOMONTH($B$2,0),I14)-MAX($B$2,H14))
I tried to change a few things and use it as an array function but it is not working. I am very new to array functions so I may be doing it completely wrong.
=SUM(MAX(0,MIN(EOMONTH($B$2,0),I:I)-MAX($B$2,H:H)))
any help is much appreciated! Let me know if you need more info too.
Bad news - you can't use MAX and MIN in an array formula like this because instead of treating H and I as two arrays it just treats them as one big long array and you only get one value out of them.
You also need to add 1 to your original formula because if they moved in on the last day of the month (say) it should still count as one day.
If you replace the MAX and MIN with IF statements you get something like this
=SUM(IF(IF(EOMONTH($B$2,0)<IF(I2:I10="Active",TODAY(),I2:I10),EOMONTH($B$2,0),IF(I2:I10="Active",TODAY(),I2:I10))-IF($B$2>H2:H10,$B$2,H2:H10)<0,0,
IF(EOMONTH($B$2,0)<IF(I2:I10="Active",TODAY(),I2:I10),EOMONTH($B$2,0),IF(I2:I10="Active",TODAY(),I2:I10))-IF($B$2>H2:H10,$B$2,H2:H10)+1))
which has to be entered using CtrlShiftEnter
A useful tip if you are new to arrays is not to include more rows in an array formula than you need to because it will be slow, and test it first on a small number of rows so that you can step through it using Evaluate Formula if you run into trouble.
I need to write some code that compares dates in an excel file and then high lights those rows of data based on the data evaluations. Essentially there are 3 columns in this file that have a standard Month/day/year format. I need to compare the day of all three columns to see if they are within a 3 day date difference "don't care about the month". If they are not within the 3 day date difference I want to high light them. An example of an OK comparison would be (10/1/2015,12/2/2015, 8/3/2015) I would not want to do anything with this row of data. Here is what I consider to be a "bad" date comparison (10/1/15, 11/3/2015, 8/5/2015). All the dates have to be within 3 days and as you can see there is a 4 day date difference between 10/1 and 8/5. How can I write something up like this to evaluate this?
You can just compare the Max() of the days to the Min() of the days with the Array Formula:
=IF(MAX(DAY(A1:C1))-MIN(DAY(A1:C1))>3,"fail","Close enough")
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
You can do the same functionality with VBA if that is needed.