Google Sheet: In a formula, how do I refer to a range within a range? - google-sheets-formula

id
name
quantity
direction
134
bags
256
in
134
bags
1
in
134
bags
344
out
134
bags
12
in
234
books
21
out
=VLOOKUP(searchKey,filter(C1:D5,A1:A5=134),2,FALSE)
In the formula above, I want the searchKey to be a relative value based on the result of filter. For example, colum1 row4, which is number 344.
So the question is, how do I refer to a range within another range that is generated by a formula function?

Related

Sorting when compare-function could return "don't know" for certain pairs

I would like to sort objects (or possibly rows of a datase) in a certain way. Primarily based on time, but this value can be NULL. I have a second value sequence which is a number which gives an order, but it may have a number which doesn't equal the order of the time column anymore. So it should at least sort the times in order.
Let's say I have an array/db with the following content:
id time sequence
2 11:35 46
4 NULL 48
5 11:40 99
6 NULL 49
8 11:45 51
9 11:50 52
7 NULL 53
3 NULL 54
1 11:55 55
I would wantthe end-result to be like this
id time sequence
2 11:35 46
4 NULL 48
6 NULL 49
5 11:40 99
8 11:45 51
9 11:50 52
7 NULL 53
3 NULL 54
1 11:55 55
A simple compare function would look something like this (pseudocode)
int compare(a, b)
{
if(a->time !== null && b->time !== null)
return (int)a->time - (int)b->time;
return a->sequence - b->sequence;
}
But a generic sort-call will of course limit its number of compare-function calls. So if it compares ids 5/1, 5/3 and 1/3 it will have determined an order and produce this result.
id time sequence
2 11:35 46
4 NULL 48
6 NULL 49
8 11:45 51
9 11:50 52
7 NULL 53
3 NULL 54
5 11:40 99
1 11:55 55
I would like to give my compare function to say something like "don't know" for certain comparisons. Namelijk when a row with a time filled is compared to one without. So that the sort-function is forced to look further. I've tried returning 0 in that case for instance, but that doesn't solve the problem. Is there a name for this sort of mechanism? Is there a different way to solve this problem?
Clearly, you cannot sort by just comparing any two elements, because you do not have a total order.
You seem to be very sure of the resulting order though.
Let's take another instance, because expectations are unclear to me:
id time sequence
2 11:35 103
5 11:40 51
8 11:45 28
9 11:50 50
1 11:55 99
where should all the NULL time go and why?
4 NULL 48
6 NULL 49
7 NULL 53
3 NULL 54
It seems difficult to find a rule for placing the NULL once we sorted the non NULL!
What probably better fits your expectations is the result from a procedural algorithm, like this for example:
sort by sequence first
then let well defined times move up as long as there is a larger time above
Written like this, Stage 2 looks like a bubble sort restricted to indices with non NULL times... You could call that a sparse bubble sort.
The resulting order is always the same whatever the original order, so it is not ambiguous.
I think that it's because stage 1) is a total order.
If you would introduce NULL in sequence column, I'm not even sure that you would end up with a non ambiguous sort...
Maybe you can call that a multi-stage partial sort.

Finding maximum and minimum value in a matrix column using Octave

I have a 10 x 2 sample matrix as follows
2104 3
1600 3
2400 3
1416 2
3000 4
1985 4
1534 3
1427 3
1380 3
1494 3
I need a generalized method to find the minimum and maximum value in a column.
I can use
max(max(X)) to find the maximum value in a matrix, but not of a column.
Also, max(min(X)) to find the minimum value is not a generalized solution.
Given a matrix X, max(X) will return the maximum value in each column. You can index the result to get the value for a given column:
max(X)(1) % max of the fist column (doesn't work in MATLAB)
Alternatively, extract the column and get its max:
max(X(:,1)) % max of the fist column
max (and many similar functions) operate on columns by default. To get the maximum of each row, use max(X,[],2).

How to make a regression model efficient?

I am using the first three column as three different independent variables and trying to find the value of dependent variable which is in the fourth column. Here is a piece of data and results. With these details, I am trying to formulate an equation. So I used Multiple Regression model and got the following predicted value which is in the fifth column. Although for some data, the model is right, It is not right for most of the results. How can I use the data I have to create a model or equation in generic form? Is there anyways to improve this? I used confidentiality limit of 95%
255 216 0 0.106 0.264531693
255 255 255 0.144 0.146814881
1 255 255 0.158 0.278869742
168 168 168 0.186 0.341845818
0 255 1 0.229 0.33885068
254 106 0 0.26 0.428702478
0 148 254 0.324 0.438811419

Sum up custom grand total on crosstab in BIRT

I have a crosstab and create custom grand total for the row level in each column dimension, by using a data element expression.
Crosstab Example:
Cat 1 Cat 2 GT
ITEM C F % VALUE C F % VALUE
A 101 0 0.9 10 112 105 93.8 10 20
B 294 8 2.7 6 69 66 95.7 10 16
C 211 7 3.3 4 212 161 75.9 6 10
------------------------------------------------------------------
GT 606 15 2.47 6 393 332 84.5 8 **14**
Explanation for GT row:
Those C and F column is summarized from the above. But the
% column is division result of F/C.
Create a data element to fill the VALUE column, which comes from range of value definition, varies for each Cat (category). For instance... in Cat 1, if the value is between 0 - 1 the value will be 10, or between 1 - 2 = 8, etc. And condition for Cat 2, between 85 - 100 = 10, and 80 - 85 = 8, etc.
The GT row (with the value of 14), is gathered by adding VALUE of Cat 1 + Cat 2.
I am able to work on point 1 and 2 above, but I can't seem to make it working for GT row. I don't know the code/expression to sum up the VALUE data element for this 2 categories. Because those VALUE field comes from one data element in design mode.
I have found the solution for my problem. I can show the result by using a report variable. I am assigning 2 report variables in % field expression, based on the category in data cube dimension (by using if statement). And then in data element expression, I am calling both of the expressions and add them.

What should I use as a check digit algorithm for a base 31 value?

I'm using the following set of values to create a 9 character long base 31 value:
0123456789ABCDEFGHJKLMNPQRTUWXY
I was looking at modifying the Luhn algorithm to work with my base.
My question is:
In base 10, the Luhn algorithm doubles each value in an even position and then if the result is >10 the individual digits of the result are added together.
Should I still be doubling my even position values, or using a higher multiplier?
I'm trying to protect against transposed characters, missing characters, extra characters and just plain wrong digits.
I looked into the Luhn mod N algorithm, but it is very limited in what it can validate against.
I decided to use a modified version of the Freight Container system.
The shipping container system multiples each value by 2^[position] (position starting from 0) and then performs a modulus 11 on the result to get a base 10 check digit (a result of 10 is not recommended).
In this case, the trick is to find values in the range x^0 to x^[length] which are not evenly divisible by the figure you use on the modulus.
I've decided to use 3^[position] as the multiplier and performing a modulus 31 on the sum to get the check digit.
As an example: 0369CFJMK
Character 0 3 6 9 C F J M K
Value 0 3 6 9 12 15 18 21 19
--------------------------------------------------------------
Multiplier 1 3 9 27 81 243 729 2187
Result 0 9 54 243 972 3645 13122 45927
Total 63972 MOD 31 = 19
It seems that with these sort of algorithms, the main requirement is that the multipler is not evenly divisible by the base and that the pattern of the remainders doesn't repeat within the length of the code you want to validate.
Don't reinvent the wheel - use Luhn mod N instead.

Resources