Given a column of numbers, return the row number in which the maximum value is present using LibreOffice SpreadSheet - spreadsheet

Let's say I have a column A:
A
1 | 10
2 | 20
3 | 33
4 | 42
On line 5 I can calculate the maximum of the row: MAX(A1:A4), which returns 42. In row 6 I would like to get the row number for the maximum, i.e. row number 4.
Thanks

A5 contains =MAX(A1:A4)
A6 then should have formula =MATCH(A5;A1:A4;0)
A6 returns the n'th row of the search matrix where your value can be found.
Does this help to solve your problem?

Related

Understanding window function frame with RANGE mode

SELECT
sum(unique1) OVER () AS total,
sum(unique1) OVER
(PARTITION BY four ORDER BY unique1 RANGE BETWEEN 5::int8 PRECEDING AND 6::int2 FOLLOWING),
unique1,
four
FROM
tenk1
WHERE
unique1 < 10;
return:
total | sum | unique1 | four
-------+-----+---------+------
45 | 4 | 0 | 0
45 | 12 | 4 | 0
45 | 12 | 8 | 0
45 | 6 | 1 | 1
45 | 15 | 5 | 1
45 | 14 | 9 | 1
45 | 8 | 2 | 2
45 | 8 | 6 | 2
45 | 10 | 3 | 3
45 | 10 | 7 | 3
(10 rows)
Minor change based on this
Since partition by four make each frame only 2 or 3 rows. and if you between 5 preceding and 6 following, then I thought in this case, rows/range frame doesn't matter. I thought range from, rows from will return the same result. because 5 preceding 6 following covered enough 2, 3 rows per frame.
However it does matter. I guess I do understand the same query with ROWS instead of RANGE.
Quote from manual:
In RANGE or GROUPS mode, a frame_start of CURRENT ROW means the frame
starts with the current row's first peer row (a row that the window's
ORDER BY clause sorts as equivalent to the current row), while a
frame_end of CURRENT ROW means the frame ends with the current row's
last peer row. In ROWS mode, CURRENT ROW simply means the current row.
Question: How to interpret
partition by four order by unique1 rows between 5::int8 preceding and 6::int2 following
The documentation states:
In ROWS mode, the offset must yield a non-null, non-negative integer, and the option means that the frame starts or ends the specified number of rows before or after the current row.
[...]
In RANGE mode, these options require that the ORDER BY clause specify exactly one column. The offset specifies the maximum difference between the value of that column in the current row and its value in preceding or following rows of the frame. The data type of the offset expression varies depending on the data type of the ordering column.
(The emphasis is mine.)
So with ROWS, you will get the 5 rows before and the 6 rows after the current row. With RANGE, you will get those rows where unique1 is no more than 5 less or 6 more than the unique1 of the current row.
In your example, if you consider the first row, ROWS BETWEEN ... AND 6 FOLLOWING would include the third row, but RANGE BETWEEN ... AND 6 FOLLOWING would not, because the difference between 8 (the value of unique1 in the third row) and 0 is greater than 6.

ARRAYFORMULA ON SPECIFIC CELLS

So I have this formula, it basiclly mulitiplies every value in a row for every row and sums up the products, and while thats awesome and all
=sum(ArrayFormula(iferror(A1:A*B1:B*C1:C)))
I would like if there was a way to choose what rows it multiplies and sums up, if I can put a specific letter or like tag those cells in any way and like "filter" them out so it only sums up lets say row 1,2,4 and so on and for infinity, how ever many rows Ill like to add and whichever rows I want to include!
EXAMPLE:
1: 100 4 10
2: 120 2 12
3: 125 5 10
4: 105 3 15
Not sure I fully understand the question but I believe you could solve the problem by introducing a fourth column, using "1" to indicate rows to add to the sum and "0" for rows to ignore. By extending your formula to include the new column D each row is multiplied with 1 (adding the value, since N*1=N) or 0 (ignoring the value, since N*0=0):
=sum(ArrayFormula(iferror(A1:A*B1:B*C1:C*D1:D)))
The below example data would sum row 1, 2 and 4:
1: 100 4 10 1
2: 120 2 12 1
3: 125 5 10 0
4: 105 3 15 1

Ransack search- select rows whose sum adds up to a given value

Im using ransack search with ruby on rails and trying to output random rows between 1-6, whose time adds up to a given value specified by the search.
For example search for rows whose time value adds up to 40. In this case id 12 and 14 will be returned. Any combination between 1-6 can be randomly outputted.
If a combination of 3 rows meet the criteria then 3 rows should be outputted. likewise 1,2,3,4,5,6. If no single row or combination can be found then the output should return nil
id | title | time
----+-------------------------+-----------
26 | example | 10
27 | example | 26
14 | example | 20
28 | example | 50
12 | example | 20
20 | example | 6
Note - Not sure if ransack search is the best to perform this type of query
Thanks in advance

Need query to find rows that may have 4, 5 or 6 consecutive numbers

Trying to come up with a query that will find rows that contain 4, 5 or 6 consecutive numbers.
For example: Table MyNumbers contains 6 columns of number combinations from 1 to 52.
Cloumn names are: nbr1 nbr2 nbr3 nbr4 nbr5 nbr6
Row one contains: 1 5 43 50 51 52
Row two contains: 41 42 43 44 45 52 <----- five consecutive numbers
Row three contains: 8 14 38 39 42 50
Row four contains: 1 2 3 4 15 29 <----- four consecutive numbers
Row five contains: 8 14 24 36 48 51
Row six contains: 1 2 3 4 5 6 <----- six consecutive numbers
Need to come up with a query that would find rows 2, 4 and 6 based on containing a result set where there were 4 or more consecutive numbers in that row.
I created a database that contains all possible combinations for a 6 numbers out of 52 (1 to 52). What I would like to do is eliminate rows that have four or more numbers that are consecutive. So I am not sure above would do the trick. For those that asked, I am using sql server 2008 R2.
Assuming the numbers are always increasing, and not repeating
select *
from mynumbers
where nbr4 - nbr1 = 3
or nbr5 - nbr2 = 3
or nbr6 - nbr3 = 3
I took the liberty of simplifying it to the fact that for a series of 6 consecutive numbers, there must already be a series of 4 consecutive numbers.

excel formula to display right column

I need an excel formula for this to produce the values on the right column. simple theory. to show when right values has jump by a certain value.
10 0
10 1
11 0
11 1
12 0
12 0
12 0
12 1
13 0
13 0
If I understand correctly, you want 1 when the next value is different, and zero otherwise?
If so, assuming your values are in column A, starting with A1, try the following formula in B1: =IF(A1=A2;0;1) then copy B1 and paste in the whole column B.
Make that =IF(ISBLANK(A2);0;IF(A1=A2;0;1)) to also return 0 if the next cell is blank.