In InfluxDB, I have a time series of which I would like to determine the maximum value. Using the MAX() function does return the maximum, but as a single point consisting of the maximum value and corresponding timestamp.
How can I get not just a single point, but a full series of points, each consisting of the respective original timestamp and the maximum value?
Example:
(T1, 4)
(T2, 7)
(T3, 5)
(T4, 4)
should be returned as
(T1, 7)
(T2, 7)
(T3, 7)
(T4, 7)
instead of just
(T2,7)
Related
Need help:
I have a number (let's say 550) and need to create a perfect distributed SEQUENCE of length N where SUM of numbers will give this number (550).
Something like: 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
The only input I have is the length of sequence and the final sum of it's numbers.
Thank you.
=INDEX(SEQUENCE(length;1;1)*2*sum/length/(length+1);;)
So here are some possible starting values (a) and increments (d) that satisfy the conditions where the number of terms n is 10 and the sum S is 550:
Using the formula
=MAKEARRAY(S/n,2,LAMBDA(r,c,if(c=1,r,2/(n-1)*(S/n-r))))
The formula is obtained by re-arranging the standard formula for an arithmetic progression to get d (the increment) in terms of a (the starting value, S (the sum) and n (the number of terms):
Here are the integer pairs using
=lambda(pairs,filter(pairs,index(pairs,,2)=int(index(pairs,,2))))(MAKEARRAY(S/n,2,LAMBDA(r,c,if(c=1,r,2/(n-1)*(S/n-r)))))
Here are the actual series using
=lambda(intpairs,makearray(rows(intpairs),n,lambda(r,c,index(intpairs,r,1)+(c-1)*index(intpairs,r,2))))(lambda(pairs,filter(pairs,index(pairs,,2)=int(index(pairs,,2))))(MAKEARRAY(S/n,2,LAMBDA(r,c,if(c=1,r,2/(n-1)*(S/n-r))))))
It can be verified that each series totals to 550.
Once you have the values of a and d, you can also use Sequence to generate the results:
=sequence(1,n,F10,G10)
if your issue is to divide value x into equal chunks y try:
=INDEX(SEQUENCE(B1, 1)*A1/B1)
or starting from 0:
=INDEX(SEQUENCE(B1, 1, 0)*A1/(B1-1))
Lets say I have the following column A:
X
Y
X
Z
W
Z
W
I want to write 2 formulae, one that counts the number of values that appear exactly once, and one that counts the number of values that appear more than once. So for the above column, the results would be 1 (only Y) and 3 (W, X, Z).
I tried the following formula, but got an error:
=FILTER(A:A,COUNTIF(A:A,A:A)>1)
How can I do this using Google Sheets? Please note, some column values may be empty and should be ignored.
only once:
=FILTER(A:A, COUNTIF(A:A, A:A)=1)
more than once:
=UNIQUE(FILTER(A:A, COUNTIF(A:A, A:A)>1))
I have a google sheet that I am using to try and calculate leveling and experience points. Column A has the level and Column B has the exp needed to reach the next level. i.e. To get to Level 3 you need 600 exp.
A B
1 200
2 400
3 600
...
99 19800
In column I2 I have an integer for an amount of exp (e.g. 2000), in column J2 I want to figure out what level someone would be at if they started from 0.
Put this in column J and ddrag down as required. Rounddown(I2,-2) rounds I2 down to the nearest 100. Index match finds a match in column B and returns the value in column A of the matched row.
=index(A2:A100,match(ROUNDDOWN(I2,-2),B2:B100,0))
Using a helper column (for example Z): put =sum(B$1:B1) in cell Z1 and drag down. This will compute the sums required for each level. In J2, use the formula
=vlookup(I2, {B:B, Z:Z}, 2) + 1
which looks up I2 in column B, and returns the nearest match that is less than or equal to the search key. It adds 1 to find the level that would be reached, because your table has this kind of an offset to you: the entry against level N is about achieving level N+1.
You may want to put 0 0 on top of the table, to correctly handle the amounts under 200. Or treat them with a separate if condition.
Using algebra
In your specific scenario, the point amount required for level N can be computed as
200*(1+2+3+...+N-1) = 200*(N-1)*N/2 = 100*(N-1/2)^2 - 25
So, given x amount of points, we can find N directly with algebra:
N = floor(sqrt((x+25)/100)+1/2)
which means that the formula
=floor(sqrt((I2 + 25) / 100) + 1/2)
will have the desired effect in cell J2, without the need for an extra column and vlookup.
However, the second approach only works for this specific point values.
I have a log to track my running distance/times/etc. I am trying to come up with a way to display my top 10 or so times (pace/mile) at various distances (0-2.9, 3-4.9, 5-6.9, etc). I've tried to use "Sort" and I'm able to sort by distance, but I want to be able to only select the distances within those groups, then sort based on pace. Ideally, it would display Date / Distance / Pace.
I'm not quite sure what terms I'm supposed to be looking for, so it makes it hard to find.
Here's a link to my sheet: https://docs.google.com/spreadsheets/d/1d0aOsaarKaoSJNupzyk62oDh_o1yWosoi8TldCcKs0Y/edit?usp=sharing
Basically, in the "Tests" sheet, I want to display "Best Pace 3-5 Miles" and have it sort my top 10(or whatever) runs using the "Mileage" sheet column C for distance, Column F for pace, and Column B for date.
Thanks!
Try this expression.
=sort(filter(Mileage!A10:E, (Mileage!C10:C >= 3) * (Mileage!C10:C <= 5) * (Mileage!E10:E <> 0)), 5, false)
Here is the documentation for filter
https://support.google.com/docs/answer/3093197?hl=en
and for sort https://support.google.com/docs/answer/3093150?hl=en
(Mileage!C10:C >= 3) * (Mileage!C10:C <= 5) * (Mileage!E10:E <> 0) means the value in column C must be >= 3 and <= 5 and the value in E must be different from 0.
sort(range, 5, false) means: sort the 5th column in the given range in descending order.
I have a spreadsheet that I'm starting to use for personal money analysis.
My main sheet is called "transactions" and has headers of Category, Description, Date and Amount (it's basically a check register).
I've created a pivot report off of that sheet that contains sum, min and max of Amount by Category.
I would like to make a custom average function on that pivot report but not sure how to go about it.
What I would like to see is the average amount of negative transactions between positive ones.
My positive transactions are my paychecks and the negative transactions are any spending I do.
An example might help in what I'm trying to do here...
Let's say for category "Food" I have the following transactions (in this order)...
-20
-25
-30
100
-30
-35
-40
I'd like my average to be calculated like this...
( ( (-20 + -25 + -30) / 3 ) + ( (-30 + -35 + -40) / 3 ) ) / 2
Anyone have the slightest idea on how I can enhance my pivot report to do this?
You do it with something like:
=ARRAYFORMULA(AVERAGE(IF(Sheet1!D2:D8<0,Sheet1!D2:D8, 0)))
where column D is the amount of your example and Sheet1 contains the "transactions" of your example.
If you want to fill it for the pivot table (having the category as another criterion) you can check the answer at: https://stackoverflow.com/a/9165254/179529
=SUM(ARRAYFORMULA(((Transactions!$A2:$A)=$A2) * ((Transactions!$D2:$D)>0) * (Transactions!$D2:$D) ))
/
SUM(ARRAYFORMULA(((Transactions!$A2:$A)=$A2) * ((Transactions!$D2:$D)>0) * (1) ))
where $A2 is the cell where you have the category name in the pivot table (The $ will allow you to copy the formula to other columns in you want it per month or other second criterion.
If you want to SUM the element in column D only if they great than 0, you need to have ((Transactions!$D2:$D)>0) as the second argument and (Transactions!$D2:$D) as the 3rd argument (otherwise you will count the cells instead of SUM them).
Since AVERAGE will take blank cells as well, I've used SUM/COUNT instead. Note that COUNT is actually SUM with the 3rd argument as 1.
Also note that if you want to ignore a header line you need to define your columns with Transactions!$D2:$D, to start from the 2nd row.