Computing weekly averages using Excel - excel

I have several time series for several years. Now I want to calculate the weekly average. But the problem is, that it needs to be the average from Wednesday to Wednesday. Here is a small data sample:
Date X
03.01.2005 2.154
04.01.2005 2.151
05.01.2005 2.151
06.01.2005 2.15
07.01.2005 2.146
08.01.2005 2.146
09.01.2005 2.146
10.01.2005 2.146
11.01.2005 2.146
12.01.2005 2.145
13.01.2005 2.144
14.01.2005 2.144
15.01.2005 2.144
16.01.2005 2.144
17.01.2005 2.143
18.01.2005 2.144
19.01.2005 2.143
20.01.2005 2.144
21.01.2005 2.143
22.01.2005 2.143
23.01.2005 2.143
24.01.2005 2.143
So 05.01 is a Wednesday.
How can I calculate the average for example from and with 06.01 to and with 12.01 (i.e. always 7 days)?
For this example it would be:
(2.15+2.146+2.146+2.146+2.146+2.146+2.145)/7=2.146429.

With Grouping in a PivotTable. Date for ROWS (not text format) and Average of X for VALUES. Then select a date in the PT and Group, Starting at: 06/01/2005, Days (only), Number of days: 7.

You can put week numbers (modified for Wed-Tue) in a helper column like this:
=IF(AND(MONTH(A2)=12,WEEKNUM(A2-3)=53),53,IF(WEEKNUM(A2-3)=53,1,WEEKNUM(A2-3)))
With the results in the helper column you can then use formulas like
=AVERAGEIF(C:C,1,B:B)
Where 1 is the week number you want the average for. Or better yet, throw the results into a pivot table to have it give you the averages for every week number.

Related

Function for finding duration where wave height <3m where time is between 5:00am and 6:00PM

I am trying to find duration for time where wave height is under 3m and time period is between 5:00am and 6:00pm. Trying to find this duration for a month of tidal data.
I have raw data for wave height and timestamps when it is high and low.
eg.
Timestamp Wave_Height
1/01/2022 3:16 0.68
1/01/2022 9:37 6.62
1/01/2022 16:14 1.07
1/01/2022 21:54 5.37
2/01/2022 4:06 0.59
etc…
So far I have got linear interpolation to find points where wave height=3. I am struggling to get a function to find the durations for my limits on time.
Included a picture to explain
Graph of wave data over time
The timestamps occur over different days in the month so difference between times must consider the changed dates in some cases(see rev 2 errors ####### where errors occur for changing of dates)
rev 2 error
The following should work. I have added some columns to avoid complicated formulas.
interpolate when the wave_height = 3 (column G)
add column H which is True when wave_height increases and False if it decreases (at the time in column G):
so cell H6 = F7<3 gives TRUE
add column E to limit the time window to 5:00-18:00.
E7 is =IF(D7<$G$2;$G$2;IF(D7>$H$2;$H$2;D7))
Added column I to calculate the time during wich wave_height < 3. The sum of that column is what you need.
I8 is =H8*(G8-E7)+NOT(H8)*(D8-G8)

Filtering discrepancies in duplicate measurements

I have a dataset with the following problem.
Sometimes, a temperature sensor would return duplicate readings at the exact same minute, where sometimes 1 of 2 of the duplicates is "reasonable" and the other is slightly off.
For example:
TEMP TIME
1 24.5 4/1/18 2:00
2 24.7 4/1/18 2:00
3 24.6 4/1/18 2:05
4 28.3 4/1/18 2:05
5 24.3 4/1/18 2:10
6 24.5 4/1/18 2:10
7 26.5 4/1/18 2:15
8 24.4 4/1/18 2:15
9 24.7 4/1/18 2:20
10 22.0 4/1/18 2:20
Line 5, 7 & 10 are readings that are to be removed as they are too high or low (doesn't make sense that within 5 minutes it will rise and drop more than a degree in a relatively stable environment).
The goal at the end with this dataset is to "average" the similar values (such as in line 1 & 2) and just remove the lines that are too extreme (such as line 5 & 7) from the dataset entirely.
Currently my idea to formulate this is to look at a previously obtained row, and if one of the 2 duplicates is +/- 0.5 degree, to mark in a 3rd column with TRUE so I can filter out all the TRUE values in the end. I'm not sure how to communicate within the if statement that I'm looking for a + OR - 0.5 of a previous number however. Does anyone know?
Here is a google sheet example that does what you want:
https://docs.google.com/spreadsheets/d/1Va9RjSeulOfVTd-0b4EM4azbUkYUb22jXNc_EcafUO8/edit?usp=sharing
What I did:
Calculate a column of a 3-item running average of the data using "=AVERAGE(B3:B1)"
Filter the list using "=IF(ABS(B2-C2) < 1, B2, )"
Calculate the average of the filtered list
The use of Absolute Value is what provides "+ OR -" that you were looking for. It is saying if the distance between two numbers is too much, then don't include the term.
So, A Simple Solution came to my mind. Follow the Following steps given below:
Convert Data to Table
Add a 4th column at the last
Enter the formula "Current Value - Previous Value"
Filter the Column with high difference values
Delete those rows of filtered data and you'll be left with Normal Values
Here's the ref. Image
Or If you want to consider the Same time difference only then do the following:
Convert your data to Table
Add 4th column at the end of table
Writhe the Following Formula to 4th Column
IF(Current_Time = Previous_Time, Current_Temp-Previous_Temp,"")
Filter and Delete the Data with high Difference
See the following Image:

Rolling last 3 month average column in Spotfire

I'm trying to calculate for rolling average last 3 months . i'm stuck up to this calculation and could not figure out on how to inject this in spotfire using the logic.
the first month (feb) will use the recovery% as multiplier for wip% + recovery%
for the second month (mar) will get the average of (feb) and multiply to wip% +recovery%
for the 3rd month (apr) will get the average of (feb ,mar) and multiply to wip% + recovery%
for the 4month (may) will get the avg of (feb,mar,apr) and multuply to wip% +recovery%
my ultimate goal is to create a column for rolling average 3 months to be use in barchart and cross table. any help is very much appreciated. Thank you.
attached sample table
using below code it's giving me different result. there are no data for the first 2 month (Feb and Mar) and also the average i'm getting for the 3 months rolling is including the current month which the 3months rolling will start from the previous month.
(Sum([WIP]) / Sum([Assy Input]) * Sum([Recover]) / Sum([Input])) + (Sum([Recover]) / Sum([Input]))
THEN Avg([Value]) OVER (LastPeriods(3,[Axis.Rows])) THEN If(Count() OVER (LastPeriods(3,[Axis.Rows]))=3,[Value],null) as [3 mos Rolling]

Align two time series where each has gaps

I am trying to merge two variables with different dates together using Excel. Here is an example of what I am trying to do:
Date Y Date X
03.01.2005 2.56438 03.01.2005 2.154
04.01.2005 2.57 04.01.2005 2.151
05.01.2005 2.59 05.01.2005 2.151
06.01.2005 2.61 06.01.2005 2.15
07.01.2005 2.61 07.01.2005 2.146
10.01.2005 2.62 08.01.2005 2.146
11.01.2005 2.63 09.01.2005 2.146
12.01.2005 2.64 10.01.2005 2.145
13.01.2005 2.66 11.01.2005 2.144
14.01.2005 2.66 12.01.2005 2.144
17.01.2005 2.67 13.01.2005 2.143
18.01.2005 2.67 14.01.2005 2.144
19.01.2005 2.68 15.01.2005 2.143
20.01.2005 2.6925 16.01.2005 2.144
21.01.2005 2.7 17.01.2005 2.143
24.01.2005 2.7 18.01.2005 2.143
25.01.2005 2.7 19.01.2005 2.144
X has values on dates when there is no Y value (e.g. 08.01.2005).
Is it possible to create a new column (say col5) that only contains the date if it can be found for both variables and then add the values for Y(col6) and X(col7) behind it? (I.e. in my case the date 08.01.2005 would be skipped since it can only be found for the variable X but not for the variable Y).
At the end it should look like:
Z Y X
03.01.2005 2.56438 2.154
04.01.2005 2.57 2.151
05.01.2005 2.59 2.151
06.01.2005 2.61 2.15
07.01.2005 2.61 2.146
10.01.2005 2.62 2.145
11.01.2005 2.63 2.144
12.01.2005 2.64 2.144
13.01.2005 2.66 2.143
14.01.2005 2.66 2.144
17.01.2005 2.67 2.143
18.01.2005 2.67 2.143
19.01.2005 2.68 2.144
Note that sometimes it is also the other way around, meaning there are dates with a value for Y but not for X.
Create a list of all possible dates on or between your limits, use VLOOKUP to populate an array including this list with Y and X from your source data then filter the array to delete rows that show #N/A.
If Date is in A1 and your list of dates in ColumnF starting in Row2, in G2:
=VLOOKUP(F2,A:B,2,0)
in H2:
=VLOOKUP(F2,C:D,2,0)
Copy both down to suit then select ColumnsF:H, Copy into a new sheet with Paste Special, Values and filter to delete rows containing #N/A. Copy result back if required.

Excel formula for an average where the price increases every day

Can some one help me with a simple forumla in excel for the following problem.
I need to be able to predict an average price for the month. For example, if the current price is $1000 and there are 5 days left until the end of the month, I believe the price will increase £50 p/day. 1050 then 1100 1150 etc So the average price for the last six days will be 1100?
i would like to be able to do a forumla that works it out from the current price, the increase amount and the days left with out having to have a cell for each day etc?
Is this possible? i have tried google but have come up with nothing, a difficult question to articulate.
Sounds like you're having troubles finding the days in the month and the percentage of the month that has already passed / left
To calculate the number of days in the current month use this formula
=EOMONTH(NOW(), 0)-EOMONTH(NOW(), -1)
To calculate the current day of the month use this formula
=DAY(NOW())
To calculate the percentage of the month already gone
=DAY(NOW()) / (EOMONTH(NOW(), 0)-EOMONTH(NOW(), -1))
To calculate the percentage of the month remaining
=1 - (DAY(NOW()) / (EOMONTH(NOW(), 0)-EOMONTH(NOW(), -1)))
I'm not clear what you are averaging - is it 5 days or 6?
If you start with 1000 and average 5 days then you are averaging 1000, 1050, 1100, 1150 and 1200 so the average is 1100 - if that's the required result try this formula
=A2+B2*(C2-1)/2
where A2 is price, B2 increase amount and C2 days left
If you are averaging 6 days then that starts at 1000 and ends at 1250 so average is 1125 and the formula should be:
=A2+B2*C2/2

Resources