VLOOKUP all Rows and Return all Data - excel

I am using excel 2010. I am trying to do a VLOOKUP and retrieve all values. Here is my issue - I have data with medication frequency. The frequency is listed ones; but the frequency has more than one times. Example, freq BID (twice a day) has times 0900 and 1700. When I try to do VLOOKUP, it pulling in the first value only. How do I pull in all the values?
The function =VLOOKUP(RC[-4],Sheet3!R5C1:R38C3,3,FALSE) only pulls the first row it encounters.
However, the associated FREQ has four times and notice its only pulling 00:00:00 in the above table.

If 300285 for example represents every six hours starting at midnight then a LOOKUP function could be applied to return all four daily values at one time where these are in a single wrapped cell, such as:
="00:00:00"&CHAR(10)&"06:00:00"&CHAR(10)&"12:00:00"&CHAR(10)&"18:00:00"

Related

Excel average if function for obtaining hourly data

I have minute data for air temperature and relative humidity (about 930,000 cells) for a building and I am trying to obtain the hourly average using excels "AverageIF" function. Here's the criteria that I have come up with: whenever one hour passes, average the air temperature and relative humidity for that hour. I am having trouble communicating these criteria to excel and any help would be appreciated. I have included a pic of what my data looks like:
the yellow row is me manually adding a row after an hour has passed and calculated the average using the average function.
In the example above I went a bit long winded in the formula to deal with time intervals where there was no data, as that generates a divide by 0 error.
Essentially what I did was setup a summary table to the right. I gave a start and end time for each hour (ASSUMING this is based on a 24 hour clock and not 1 hour from some arbitrary start time)
I used the AVERAGEIFS function as you have two criteria. Everything after a start time and everything before an end time. Only lines that match BOTH criteria are included.
The basic formula looks like this and is based on my example cell J4:
AVERAGEIFS(E$4:E$31,$C$4:$C$31,">="&$H4,$C$4:$C$31,"<="&$I4)
If the date is important, then you would need to add a date column to the table on the right and add a third criteria to the formula above.
In order to deal with divide by zero error and display blank instead of zero so you can distinguish between actual average of 0 and no data and still presenting an error when another type of error comes up I use the following formula in J4:
=IFERROR(AVERAGEIFS(E$4:E$31,$C$4:$C$31,">="&$H4,$C$4:$C$31,"<="&$I4),IF(ERROR.TYPE(AVERAGEIFS($E$4:$E$31,$C$4:$C$31,">="&$H4,$C$4:$C$31,"<="&$I4))=2,"","ERROR"))
The above formulas can be copied down and to the right.

How to calculate average of parent category in excel?

I have data in below format. It shows starting and end time of an activity and calculates duration accordingly. The activity is performed through out the day at different times.
I have added a pivot. I want to find out the average duration in a workday or a holiday(Day category). When I am trying to apply average in the current pivot, it is dividing the total duration by the number of sessions in a day.For example in week 1, an activity was done on 4 work days and the total duration for the activity in workdays was 04.19, I want to divide this number by 4 and find out the average time spent on each day but the pivot divides it by 11 which is the total number of sessions in the four days.
Link for data
Steps:
Add a helper column to identify how many unique pairs of Dates/Day Categories there are:
=IF(SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))>1,0,1)
You can add extra products to this formula to force extra fields to be unique to be counted as well.
SRC:Simple Pivot Table to Count Unique Values
Add a Calculated Field in the PivotTable that is:
SUM(Duration)/SUM([Helper Column Name]) and include it in the 'Values' section of the PivotTable. Due to the new column being added, you might have to re-create the PivotTable.
This should produce the average in the manner that you want.

Excel AVERAGEIFS else statement

I'm trying to perform an AVERAGEIFS formula on some data, but there are 2 possible results and as far as I can tell AVERAGEIFS doesn't deal with that situation.
I basically want to have an ELSE inside it.
At the moment I have 2 ranges of data:
The first column only contains values 'M-T' and 'F' (Mon-Thurs and Fri).
The second column contains a time.
The times on the rows with an 'F' value in column 1 are an hour behind the rest.
I want to take an average of all the times, adjusting for the hour delay on Fridays.
So for example I want it to take an average of all the times, but subtract 1 hour from the values which are in a row with an 'F' value in it.
The way I've been doing it so far is by having 2 separate results for each day, then averaging them again for a final one:
=AVERAGEIFS(G3:G172, B3:B172, "M-T")
=AVERAGEIFS(G3:G172, B3:B172, "F")
I want to combine this into just one result.
The closest I can get is the following:
=AVERAGE(IF(B3:B172="M-T",G3:G172,((G3:G172)-1/24)))
But this doesn't produce the correct result.
Any advice?
Try this
=(SUMPRODUCT(G3:G172)-(COUNTIF(B3:B172,"=F")/24))/COUNTIF(B3:B172,"<>""""")
EDIT
Explaining various steps in the formula as per sample data in the snapshot.
SUMPRODUCT(G3:G17) sums up all the value from G3 to G17. It gives a
value of 4.635416667. This after formatting to [h]:mm gives a value
of 111.15
OP desires that Friday time be one hour less. So I have kept one hour less for Friday's in the sample data. Similar SUMPRODUCT on H3:H17 leads to a value of 4.510416667. This after formatting to [h]:mm gives a value
of 108.15. Which is exactly three hours less for three occurrences of Fridays in the sample data.
=COUNTIF(B3:B17,"=F") counts the occurrences of Friday's in the B3:B17 range which are 3 occurrences.Hence 3 hours have to less. These hours are to be represented in terms of 24 hours hence the Function COUNTIF() value is divided by 24. This gives 0.125. Same is the difference of 4.635416667 and 4.510416667 i.e. 0.125
Demonstration column H is for illustrative purposes only. Infact Friday accounted values that is 108.15 in sample data has to be divided by total data points to get the AVERAGE. The occurrences of data points are calculated by =COUNTIF(B3:B17,"<>""""") with a check for empty columns.
Thus 108:15 divided by 15 data points give 7:13 in the answer.
Revised EDIT Based upon suggestions by #Tom Sharpe
#TomSharpe has been kind enough to point the shortcomings in the method proposed by me. COUNTIF(B3:B172,"<>""""") gives too many values and is not advised. Instead of it COUNTA(B3:B172) or COUNT(G3:G172) are preferable. Better Formula to get AVERAGE as per his suggestion gives very accurate results and is revised to:
=AVERAGE(IF(B3:B172="M-T",G3:G172,((G3:G172)-1/24)))
This is an Array Formula. It has to be entered with CSE and further cell to be formatted as time.
If your column of M-T and F is named Day and your column of times is named TIME then:
=SUMPRODUCT(((Day="M-T")*TIME + (Day="F")*(TIME-1/24)))/COUNT(TIME)
One simple solution would be to create a separate column that maps the time column and performs the adjustment there. Then average this new column.
Is that an option?
Ended up just combining the two averageifs. No idea why I didn't just do that from the start:
=((AVERAGEIFS(G$3:G171, $B$3:$B171, "F")-1/24)+AVERAGEIFS(G$3:G171, $B$3:$B171, "M-T"))/2

Time series mock data generation for 16 years of quarterly data in Excel or Matlab

I would like to generate a mock time series quarterly dataset from, say, 2000-2016 for a variable (quarterly credit growth) that averages around a certain value (say, 30%). Can anyone give a suggestion on how to do this in principle?
Edit: what I was implying were the actual data values for each time period, i.e. data with a certain mean and variance.
Found a solution with a code in Matlab, for anyone interested, see below in answers.
Excel approach:
You can make column A your date list. In A1, or A2 or more if you have header rows, you will have to seed your list by providing the first start date. Lets assume you put your seed date in A2. I would then go about adding 3 month to you start date using a formula, and copy down until you have hit your desired date. In order to add the 3 months I would use the following in A3.
=date(year(A2),Month(A2)+3,day(A1)
that will give you the first day of the month every 3 months. If you want the first day of the month every 3 months, set the day to 1 like so:
=date(year(A2),Month(A2)+3,day(A1)
And end of month could be calculated as:
=eomonth(date(year(A2),Month(A2)+3,day(A1)),0)
however I would prefer to do the end of month calculation based on the row you are in so I would do it more like:
=EOMONTH($A$2,(rows($A$2:A3)-1)*3)

Excel Time calculation based on just one column?

I have an excel sheet having time Column. I want to calculate the total time.
The excel column look like this:
Time:
2:14:53 , 2:15:53 , 2:16:53 , 2:19:53 , 2:29:53 , 2:41:53 , 2:59:53
Now I want to calculate the total time without adding any extra column or whatever ?
If the times are time stamps and you're only interested in the delta between the first and the last entry, simply use =A7-A1 - this will return the delta. In case it span across multiple days and you're only interested in the delta "on the watch", use =MOD(A7-A1,1). Note that sometimes the result might be displayed as a normal numeric value (in this example 0.03125instead of 0:45:00). In this case, simply change the format to Time.
In case you're talking about lap times and you want to sum them up, you can simply do this with a SUM formula: =SUM(A1:A7) will return you the total time.
Here's your example:

Resources