Rolling Time LookBack Calculation - excel

I'm sorry if this has been answered. I've been searching around for awhile now.
I have a times series dataset that I need to perform calculations on based on the previous x time (last hour,day, etc).
My issues is that I don't know how to run these calculations since the time deltas are not standardized.
Example:
Column A - Time (in seconds lets say)
Column B - Value
Time Value Result(5)
01 3 0
02 5 3
04 4 8
07 8 9
09 6 12
13 4 6
14 4 10
15 1 8
22 9 0
33 7 0
How could I return the Result(5) column by summing the last 5 seconds from that one instance (row) (not including it)?
Thank you.
EDIT:
To clear up what I'm trying to do:
1) Find the previous 5 secs of data using column A and return that range of rows
2) Using that range of rows for the 5 previous secs, sum column B
3) Output in Column C (formula)

The following formula should do what you need (paste into C2 and drag down):
=SUMIFS($B$2:$B$11,$A$2:$A$11,">="&A2-5,$A$2:$A$11,"<"&A2)
Where YourTime is the time in the row you wish to look back and sum over.
I've tested and it works for the data you provided - expand the ranges as appropriate.

Related

Excel: how to average with condition

We have an Excel sheet in which we collect some monthly data.
Each line contains a date and some value (in my boiled-down example here the date is always the first of each month and the values are [1..n]).
I am now trying to calculate an average of the values but not from ALL values but only those from the last quarter (i.e. where Date is >TODAY()-90).
TODAY() at the time of this writing is Jan. 30th, 2023, so I would expect the result to be 12, i.e. the average of the values for the last 3 months (11, 12, and 13).
A B
1 Date Value
2 01.01.2022 1
3 01.02.2022 2
4 01.03.2022 3
5 01.04.2022 4
6 01.05.2022 5
7 01.06.2022 6
8 01.07.2022 7
9 01.08.2022 8
10 01.09.2022 9
11 01.10.2022 10
12 01.11.2022 11
13 01.12.2022 12
14 01.01.2023 13
15
16 Avg. last 3 months:
17 #VALUE! <-- =AVERAGE(IF(A2:A14>(TODAY()-90);B2:B14;0))
18 #DIV/0! <-- =AVERAGEIF(A2:A14;">(TODAY()-90)";B2:B14)
I tried several approaches using AVERAGE(...) and AVERAGEIF(...) functions as shown above (and also several other variants) but I could not manage to get this working. All I ever get are error messages like #VALUE! or #DIV/0! :-(
Any idea how I can convince AVERAGE(IF) to only consider those values where the date is >today-90 days?
As per my comment:
=AVERAGEIF(A2:A14,">="&TODAY()-90,B2:B14)
Where the ampersand calculations operator is just a less-verbose way to concatenate different values. Here the 2nd parameter takes a string so using both parts on the left and right of the operator we create a value such as ">=12345".

When column number cycles to first number alter column B with new id

I have a list of numbers that I need to map across two columns. Column A has a list of numbers that repeat every 1400 records, eg.
A
B
C
12
12
12
428
12
6
12
12
14
14
14
14
12
12
12
12
12
14
14
14
I need to auto fill column B based on column C's data.
Column B should look like:
A
B
C
12
12
12
12
12
428
12
12
6
12
12
12
12
14
12
14
12
14
12
14
12
12
428
12
428
12
428
12
428
12
428
14
428
14
428
14
428
Is there a formula that I can use to accomplish this? Column C has multiple records that I need to map to column A.
Every time Column A "REPEATS", in this case when 12 comes around again, I want column B to populate with the next number. In this case 428 then 6 ect.
If the number of the repeated elements is always the same you can just divide the row number by that and index the elements in the C Column accordingly.
I.e. you have the sequence 12,12,12,12,12,14,14,14,14,14 which is of size 10. Then you can do this for the entries in column B:
=INDIRECT(ADDRESS(QUOTIENT(ROW()-ROW(B$1),N)+1,3))
Here ROW() is the row value of the cell. I supposed your numbers started from cell A1 and B1, otherwise you need to replace ROW(B$1) with the starting cell. The $1 prevents the 1 to increment when you drag the list. Then, you take the quotient of that value with N, where N is the size of the sequence, in your case it is 10. The quotient gives you the integer part of the division. To that number you need to add 1, since excel starts indexing from 1 and not from 0. Then you need to find the reference for the right address of the values you want to put in column B, this is done with ADDRESS(ROW_NUMBER,COLUMN_NUMBER), where COLUMN_NUMBER here is 3, since C is the third letter. (Change accordingly if you use a different column for the input) The ROW_NUMBER is the number we calculated. INDIRECT(ADDRESS) is a function that puts the value of the address that we got with the ADDRESS function.
This should work if your sequence of 12s and 14s is always of the same length. Otherwise, I suggest you leave excel and start using some programming language, such as python.

count and sum function not properly working

I am working in excel and for some reason my sum or count function is not working properly. Or, perhaps I am not using the correct function or in the right way.
A B C D E F G H
February Max March Max
1 28
2
3
4
5
7
11
15
17
19
22
23
25
IF(SUM(A:A>0),28,"")
IF(SUM(E:E>0),31,"")
I have the above columns, I want the Max columns to show a specific number only if there is data in their respective month column. February has data, so it shows 28. March does not have any data so it shows no max. I need to look at the entire column or at least a large area (row 2 to row 2000).
The issue I am having is that if I do not have a value in the first row, but do have values in later rows, the sum or count function will to recognize that and will return zero.
A B
February Max
3
4
5
7
11
15
17
19
22
23
25
IF(SUM(A:A>0),28,"")
I have tried both sum and count functions, neither are giving me the results I want. I have also tried making >= 1. I found from StackExchange that someone was having a similar problem and a solution was to change the cell format to a number. That did not work either. Any suggestions?
Per my comment, you could use COUNTA() which checks if a cell is blank.
While it doesn't answer the technical reason SUM/COUNT isn't working, it should work for your intended purposes.
=IF(COUNTA(A:A)>0,28,"")

Compare cell in excel

i have some data like below in one column.
Value
-----
A#show
20
20
B#show
20
25
30
C#show
10
10
10
10
D#show
10
E#show
10
20
I want to compare the values between the cell where the last string is "show" and if there is only one then no comparison.
Value Comparison
----------------------
A#show Same
20
20
B#show different
20
25
30
C#show same
10
10
10
10
D#show only one
10
E#show different
10
20
I think it's can be possible using a VBA script
It's a bit unclear what you're trying to compare between values. However, there is a way to do this without VBA.
1) In the Second Column, create a "Header" column which names which header each value belongs to. The first entry would just be A#show, but then the following would be:
=IFERROR(IF(A2*1>0,B1),B2)
2) In the third column, you can utilize countif to see if the header has more than 2 entries (indicating it has a comparison). Here is where you can apply whatever comparative metric you'd like. If it's something unformulaic, just use a pivot table with the 3 columns.

Time Lookback Calculation

I have two columns:
Column A: Time (seconds from midnight)
Column B: Value (arbitrary value I've created)
How would I find the average value (column B) at any instance in time(row) looking back over the previous x seconds (column A)?
Lets assume A1 = Seconds after midnight
Seconds after midnight Value
0 27
2 29
6 2
16 29
20 19
24 4
34 2
40 1
44 4
54 12
64 12
71 3
81 30
91 21
92 1
93 27
97 12
104 30
112 25
Note that time deltas are variable so I can't just look at the last x rows.
A specific question would be:
In a new column (column C) return the average Value of the last 10 seconds of data.
I have no idea how to do this. Can anyone help? It'd be greatly appreciated.
EDIT:
The output in the first 4 rows of column C would be:
Seconds after midnight Value Result
0 27 No values prior to this one
2 29 27 Average(B2)
6 2 28 Average(B2:B3)
16 29 2 Average(B4)
For each row, I'm taking the current time (16 in the last case)...going back x seconds (10 seconds in this case) and then averaging the values from all the cells in that time range (not including the current value).
My main issue is the time calculation. I don't know how to calculate it as I roll forward in time and I continue to get more instances as we move forward. If we go 10 seconds without any new data point then there would be no output since. If we got one instance in the previous 10 seconds then the output would be that value. If we got 100 instances in the previous 10 seconds, I need to return the average of that 100 instances.
Again, I'd appreciate any help, hints, links. This is driving me crazy.
Try the following formula in cell C3:
=IFERROR(SUMIFS(B:B,A:A,"<"&A3,A:A,">="&A3-10)/COUNTIFS(A:A,"<"&A3,A:A,">="&A3-10),0)
SUMIFS will get the sum of all values for which the seconds are:
less than A3 (i.e. less than 2 in this case)
more or equal to A3-10 (i.e. above -8 in this case)
And this sum is divided by the number of lines found with the same criteria.
If now there is an error (more specifically when the COUNTIFS returns 0, you would get #DIV/0!) you simply get 0 instead of the error.

Resources