Calculating Multiple Averages - excel

It's my first time posting a question to this forum. Though I have found answers here many times before, I have been unable to find a solution to my current predicament.
I work in a call center and each week I need to analyze data from the thousands of call that took place over the week. I'm new to programming in Excel-VBA but I've been able to get pretty far.
The data is produced by a third party program and the format is nigh unreadable. Much of the programming I've done so far has been geared towards making the data more organized. Now, I'd like to get into more analysis.
The data is arranged by employee number (NOT in order, though). Each employee takes several calls over the course of the week, some for which the customer takes a survey. It's the survey scores I want. I want to take the average of all the surveys for each employee and then display that average in the same row as each of the entries.
Example
The yellow highlighted area is what I want to add. Any ideas? Thanks for any help in advance!

No need for VBA. If you have the supported version of Excel you can use AVERAGEIF. If not you can use below formula.
Enter as an array formula by pressing Ctrl+Shift+Enter when exiting cell edit mode (instead of just enter).
=AVERAGE(IF($A$2:$A$13=A2,$B$2:$B$13))
Then copy down for all rows.

Related

Subtracting times across a day in excel

I am working on the capstone project in of the Google Career Certificate in Data Analytics. I am using Microsoft Excel. I have to calculate the ride length based on the start and end ride times. I've inputted the formula =F2(end time)-D2(start time) which returns the ride length. Going through my entire list I have some areas where the start time is like 11pm and the end time is 1am and this is returning ###### because it is a negative number with the regular formula. I've found a modified formula that can kind of do the conversion I am looking for but it is still a bit problematic. The modified formula is =(F2-D2+(F2<D2))*24 and it seems to give an accurate ride length if I reformat the answer to number. The issue is the rest of my data is in time format and the modified ones are in number format. If I convert the number values to time, the ride length values are inaccurate.
It is tricky to make the numeric value change as well due to me using a formula. I can correct them one by one after I save Excel and it no longer stores the numbers as the formula, but there are lots of data points to change and that would be time consuming. I'm hoping to find a more concise way to solve this problem. Maybe with a better formula.
[Snippet of the chart 1
Just like everything in life, there are multiple ways to achieve things. I would have formatted the date and time into a single cell; but. if you're gathering the data from another source, that's understandable.
A simple IF statement here will work. IF the days are one apart, then take '1' day off the starting time, else do your original formula:
=IF(E4-C4=1,F4-(D4-1),F4-D4)

Summing up cohort behavior cumulatively by date ranges without offsets in excel

I think this problem, when solved by creating additional charts with offsets, is easy. I want to cut out the middle man and not use offsets (unless they are useful to the answer). I have data for daily cohorts and I know specific information about their behavior 1 day later, 2 days, 3 days ect.
Now it is rather easy to make a waterfall chart of day by day activity like so...
What I want to do is skip this step (directly above, the waterfall chart) in hopes of shrinking my current workbook by a substantial amount. You can imagine having simply 1 year of data across multiple channels measuring even 1 aspect of behaviors can account for a lot of data and pivot charts. Also, btw, I have the top chart as a pivot thus allowing this to be hands off when calculating what I am looking for.
What I seek - I look to further construct groups of days as other cohorts to examine (for example, say, 1/1 - 1/5) and see what their activity has been in a cumulative fashion since then. To be more specific, I want a table that will show cohort 1/1-1/5's activity in the date range 1/1-1/5 (11) and then their activity from 1/1-1/9 (24, an additional 13 "behavior points" summed).
So far, as I said, my current solution involves the "blue arrow" schematic where an additional table is constructed and I can sum on, essentially, rectangles build by using OFFSET on sell ranges with the MATCH function. I am stumped with how to go about this without the additional charts.
Thanks!
VBA would better for this, but use this formula in C30:
=IFERROR(SUM(SUMIF(OFFSET(OFFSET($B$1,$A30-MIN($B$2:$B$10),MIN($B$2:$B$10)-$A30+DAY(C$28)),SEQUENCE($B30-$A30+1),IF(COLUMN(OFFSET($B$1,$A30-MIN($B$2:$B$10),MIN($B$2:$B$10)-$A30+DAY(C$28)))-SEQUENCE($B30-$A30+1,,0)>COLUMN($B$1),0-SEQUENCE($B30-$A30+1,,0),COLUMN($B$1)-COLUMN(OFFSET($B$1,$A30-MIN($B$2:$B$10),MIN($B$2:$B$10)-$A30+DAY(C$28)))+1),1,IF(COLUMN(OFFSET($B$1,$A30-MIN($B$2:$B$10),MIN($B$2:$B$10)-$A30+DAY(C$28)))-SEQUENCE($B30-$A30+1,,0)<=COLUMN($B$1),(C$29-C$28+1)-SEQUENCE($B30-$A30+1,,-(COLUMN(OFFSET($B$1,$A30-MIN($B$2:$B$10),MIN($B$2:$B$10)-$A30+DAY(C$28)))-COLUMN($B$1)-1)),C$29-C$28+1)),"<>")),0)
and this in D30:
=C30+SUM(SUMIF(OFFSET(OFFSET($B$1,$A30-MIN($B$2:$B$10),MIN($B$2:$B$10)-$A30+DAY(D$28)),SEQUENCE($B30-$A30+1),IF(COLUMN(OFFSET($B$1,$A30-MIN($B$2:$B$10),MIN($B$2:$B$10)-$A30+DAY(D$28)))-SEQUENCE($B30-$A30+1,,0)>COLUMN($B$1),0-SEQUENCE($B30-$A30+1,,0),COLUMN($B$1)-COLUMN(OFFSET($B$1,$A30-MIN($B$2:$B$10),MIN($B$2:$B$10)-$A30+DAY(D$28)))+1),1,IF(COLUMN(OFFSET($B$1,$A30-MIN($B$2:$B$10),MIN($B$2:$B$10)-$A30+DAY(D$28)))-SEQUENCE($B30-$A30+1,,0)<=COLUMN($B$1),(D$29-D$28+1)-SEQUENCE($B30-$A30+1,,-(COLUMN(OFFSET($B$1,$A30-MIN($B$2:$B$10),MIN($B$2:$B$10)-$A30+DAY(D$28)))-COLUMN($B$1)-1)),D$29-D$28+1)),"<>"))
And copy both down.
If one does not have the dynamic Array formula SEQUENCE() then replace all the SEQUENCE($B30-$A30+1) and SEQUENCE($B30-$A30+1,,0) with ROW($ZZ$1:INDEX($ZZ:$ZZ,$B30-$A30+1)) and (ROW($ZZ$1:INDEX($ZZ:$ZZ,$B30-$A30+1))-1) Respectively, and use Ctrl-Shift-Enter instead of Enter when exiting edit mode.
I was able to collaborate on a solution. I am told that it will be highly inefficient at scale but it gets the job done. It ss less automation-friendly but can be formulated to capture data not currently present on a, say, a pivot table that you call to update later by extending the area that the formula works on.
Formula in in I31:
=SUM(IF(($C$1:$O$1+OFFSET($B$2,$G31-$B$2,0):OFFSET($B$2,$H31-$B$2,0))>=I$29,OFFSET($C$2,$G31-$B$2,0):OFFSET($O$2,$H31-$B$2,0)))-SUM(IF(($C$1:$O$1+OFFSET($B$2,$G31-$B$2,0):OFFSET($B$2,$H31-$B$2,0))>I$30,OFFSET($C$2,$G31-$B$2,0):OFFSET($O$2,$H31-$B$2,0)))

Need to convert / transpose from row-based to column-based

Help needed please!
I’m building a parkrun spreadsheet and need help with one column. A friend of mine has a spreadsheet of his parkruns where he has successfully achieved this calculation, but he records them horizontally, whereas as I do mine by column, as per most databases. I have managed to adapt the other columns in my spreadsheet from his example, except for the ‘Tourist Streak’ # one (highlighted in yellow). I just wonder if someone could get this working in my column version please?
The Tourist Streak calculation is defined as follows: The highest number of consecutive different events attended
This one is driving me crazy!
My friend’s row-based version is here
My column-based version is here
Thanks in advance!
I thought I would have a go at this, but ended up using a different formula. The idea is that the countif looks back only to the beginning of the current sequence of unique venues to see if the current venue is duplicated and resets the length of the sequence according to the last appearance of this venue if so (I have used the word 'venue' to avoid confusion with 'run' meaning a sequence).
Starting with 1 in B2, place this formula in B3:
=IF(COUNTIF($A2:INDEX($A:$A,ROW()-B2),$A3)=0,B2+1,
ROW()-AGGREGATE(14,6,ROW($A$2:$A2)/($A$2:$A2=$A3),1))

Marking an Excel Spreadsheet with a value range

I teach a budgeting course for my professional association. As part of that course, students are required to submit a draft budget as part of their marks. The budget template that I have to use is kindof set in stone. The association offers it's courses at various college locations and I can't just arbitrarily change it's contents.
That being said, marking this assignment is a pain in the neck! I'm looking for an easy way to be able to compare the values in a cell, and then mark it correct or incorrect, if it is within an expected range..
For example, students are required to estimate the expenses for the current year. If their estimate is within $200 +/- of what the answer key states, then I would mark their answer correct.
I am not a coder by trade, but rather an armchair coder who will search out and self teach what I need to solve my problem, so I'm not afraid of a bit of homework myself. I have not been able to find any solution so far. Right now, my students submit their assignment hardcopy, and I manually mark their spreadsheets. Tedious to say the least. Any searches I try to perform for academic marking of an Excel spreadsheet only return solutions to use Excel as a tracking tool for student marks, which is not what I'm looking for.
My college uses Desire2Learn as their online platform for content delivery, and students can submit their material electronically, I want an easy way to determine if they have completed the spreadsheet correctly.
Any help, or pointers in the right direction would be greatly appreciated!
There are probably several ways to tackle this problem but this might be something simple if the layout of the sheets doesn't change. You could create a worksheet with 3 sheets.
1. a sheet to copy their work into
2. "Master" sheet with the correct answers
3. "Grading" sheet that has formulas that calculate the difference (possibly within a range). For example IF(ABS(Sheet 1!B20 - Sheet 2!B20)>200,"Correct","Incorrect"). Calculates the absolute value of the difference between the same cell address on 2 different sheets then compares to the expected answer and returns Correct or Incorrect.
You would still have to copy their work into your master worksheet one at a time. Remember this only works if their worksheet layout doesn't change.
Post a rely along with a sample of the data if you need something more flexible.

Best short examples of the need for Excel VBA [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Here's one for Joel...
I am looking for ways to demonstrate to an Excel user (with no programming experience) how learning some Excel VBA can make their life working with Excel a little easier.
First thoughts are to use an example that replicates manual tweaking of a spreadsheet, such as one click conditional formatting of all the data. For example: highlighting all the numbers red, orange or green according to user input thresholds coupled with some other derived data such as current business week.
I am hoping that such a short VBA example should not be too difficult to grasp for someone who has never written a line of code before, and hopefully make a case for trying to learn a bit of Excel VBA.
However, with this example the time taken to code it is not significantly quicker than applying the conditional formatting manually in Excel. So I would be interested to know if anyone in the community has any more elegant examples that demonstrate the advantages of using Excel VBA.
Ideal examples would have the following characteristics:
Significant time savings (large T, where T = time for manual procedure / time to code).
Non-abstract, everyday spreadsheet examples.
End results that can not be easily achieved manually.
Achievable with short, basic VBA code.
Bear in mind that the target audience is taking their first steps into programming.
If you can, watch them use Excel for a 1/2 hour and you'll find the perfect opportunity. When they open that one spreadsheet, autofit all the columns, format col A as a date, right justify col J, delete rows 2 through 5, and change the print orientation to landscape then you've found a winner. Have them do it again, but with the macro recorder on. Then replay the macro recorder.
By working with something they use in real life, it will have more impact.
You don't have to save them 1/2 hour a day with the first shot. Save them 30 seconds of drudgery on something they'll use and they'll start thinking of all the things they want automated. In my experience, they'll go overboard rather quickly. In no time, they'll want Excel to go fill out a web form, import the information, and get them a coffee.
Create your own "function" with VBA that you can use like another function from within the sheet.
You can do things that are not possible in plain Excel, or very hard to implement or reuse.
An example:
In VBA create a new module, add code like this:
Public Function SizeOfFile(a As String)
SizeOfFile = VBA.FileLen(a)
End Function
And you can now use SizeOfFile in a formula in a cell.
If cell A1 contains the name of a file, B1 fill with =SizeOfFile(A1) to get the size.
Also
You can show recording (and editing) a macro, to repeat steps that you do often.
Are the people in the target audience power users?
If so, how about combining data from multiple workbooks using external references? I'm not sure if external references are the best way to do this, and I'm not sure how difficult this would be for someone new to VBA, but that's what I ended up doing in the past.
Example 1
There are many excel files following a naming convention:
c:\data1.xls
c:\data2.xls
c:\data3.xls
I wanted to be able to enter the ID numbers in one column and have a VBA to get the data for me for all the other columns. I chose to do this with external references because then I didn't need to worry about opening and closing files and worrying about whether or not those files existed.
I wanted the result to look like this:
id data hyperlink
1 extRefA1 c:\data1.xls
3 extRefA1 c:\data3.xls
500 extRefA1 c:\data500.xls
I didn't need VBA to make the hyperlink, but I couldn't find an easy way to make external references without VBA. I tried using INDIRECT, but the referenced workbook had to be opened for INDIRECT to work. So, I used VBA to create the external references.
Example 2
This one is similar to Example 1, but I had to combine different chart data.
The data in each excel file were in columns:
X Y
1 5
2 10
3 5
4 60
I wanted the combined chart data in rows:
1 2 3 4
data1 5 10 5 60
data3 30 60 4 2
data500 25 45 20 5
So I made a VBA that put a formula array containing an external reference in a TRANSPOSE.
The data1 formula array looked something like this:
=TRANSPOSE('c:\[data1.xls]Sheet1'!$B$2:$B$5)
I don't know how others use Excel and VBA, but these proved to be extremely useful to me.
Francis
My first tentative steps into VBA were taken after I joined a company and saw one of my new team spending 30 minutes each morning compiling a report from a list of about 1,000 items that needed auto-filtered in different ways to produce the required counts. A few hours mucking about with VBA had the task down to a button click and about a second.
Anything like this that involves a loop is going to satisfy your first criteria of a significant time saving. Perhaps a task that involves extracting the area codes or house numbers from a list of 200 phone numbers or addresses?
Here is an awesome msdn link for this question.
http://msdn.microsoft.com/en-us/library/aa203714(office.11).aspx
has everything you need for a short preso.

Resources