Google Sheets QUERY with dropdown menu + multiple conditions - google-sheets

I have this kind of table on a tab (called "Log"):
A B C D E F G H
a1 b1 c1 d1 5 f1 g1 h1
a2 b1 c2 d1 3 f2 g2
a3 b2 c1 d2 4 f3 g3 h2
a4 b1 d1 5 f4 g4
a5 b2 c3 d1 3 f5 g5 h3
On another tab (called "Watch") of the same file I have a dropdwon menu with all the "D"s.
I'm trying, on the "Watch" tab, with the QUERY function to visualize C,E,G and H. C,E and H have to always be visualized while I need G only if "E"s are between "1" and "3".
The closest I got was this:
=QUERY(Log!B:H, "SELECT C,E,H,G WHERE D='"&B1&"' and H is not null and E<=3")
but it shows only where "E"s are <=3 ignoring the choice from the dropdown menu (WHERE D='"&B1&"')

try:
=QUERY(Log!B:H,
"select C,E,H,G
where lower(D) = '"&TRIM(LOWER(B1))&"'
and H is not null
and E<=3", 0)

Try with this:
=filter({Log!C1:C5,Log!E1:E5,Log!H1:H5,arrayformula(if((Log!H1:H5="")*(Log!E1:E5<=3),Log!G1:G5,""))}, Log!D1:D5="d1")
or
=filter({Log!C1:C5,Log!E1:E5,Log!H1:H5,arrayformula(if((Log!H1:H5="")*(Log!E1:E5<=3),Log!G1:G5,""))}, Log!D1:D5 = B1)
or
=filter({Log!C1:C5,Log!E1:E5, Log!H1:H5,if((Log!H1:H5="")*(Log!E1:E5<=3)=1,Log!G1:G5,"")},Log!D1:D5="d1")
The Result:
c1 5 h1
c2 3 g2
5
c3 3 h3

Related

Check if cell is contained in group of cells to add its value to another cell

I have a Google Sheets document that looks like this:
A B C D
1
2 X X 3
3 Z Y 2
4 W Z 6
5
How can I do so that if the element in column A is one of the elements of column B, its corresponding value in column C is added to column D? In this case, column D must have this values:
D2 = 3, because X is in column B
D3 = 2, because Z is in column B
D4 = 0, because W is not in column B
Many thanks in advane!
use:
=INDEX(IF(A2:A="",,IFNA(VLOOKUP(B2:B,
FILTER(B2:C, COUNTIF(B2:B, A2:A)), 2, 0))*1))
You could use:
=INDEX(IF(A2:A="",,COUNTIF(B2:B,A2:A)*C2:C),,)

Custom formula in conditional formatting rule sometimes works wrong

I am using the formula = C2 + B2 <> A2 to highlight the cells where this condition is true. For some reason, this formula does not work correctly in some cells. For example, in cells C1, C17.
Please understand the reason.
All numbers in columns A through C are integers.
Your formula is using relative references, but not the right ones. In row 1 you want to compare the values in row 1, in row 2 values of same row and so on.
In your image you've selected C1 and the rule there should be = C1 + B1 <> A1, not = C2 + B2 <> A2
C1 is being highlighted because C2 + B2 is not equal to A2. 12115+460=12575, which is different from 12573.
Same for C17. Your conditional formula is looking 1 row below. Try using
= C1 + B1 <> A1

how to run formula for a range (like a loop) and sum the results?

In google sheets, I am using a formula like this:
=SUM(
VLOOKUP(D2,I2:J8,2,FALSE) * E2,
VLOOKUP(D3,I2:J8,2,FALSE) * E3,
VLOOKUP(D4,I2:J8,2,FALSE) * E4,
VLOOKUP(D5,I2:J8,2,FALSE) * E5,
VLOOKUP(D6,I2:J8,2,FALSE) * E6
)
How to write it as a range? like
=SUM(VLOOKUP(x,I2:J8,2,FALSE) * y)
x is D2 to D6
y is E2 to E6
Try this:
=arrayformula(SUM(VLOOKUP(D2:D6,I2:J8,2,FALSE)*E2:E6))

Split huge F# file with mutually recursive functions

In F# I have a very long code file like
let rec f1 a1 a2 a3 a4 a5 .. aN =
...
and f2 a1 a2 a3 a4 a5 ... aN =
...
and f3 a1 a2 a3 a4 a5 ... aN =
...
and f40 a1 a2 a3 a4 a5 ... aN =
...
In other words there are many mutually recursive functions, each with a lot of parameters.
Now the problem is that the file is 17000 lines long, and Visual Studio has become too slow. (For example, I can't hover the mouse over an item to see its type; if I press the dot, there is no completion, and so on)
Therefore I need to split the file into many smaller files. But I can't see a mechanical and easy way to do it.
Could you please give me an advice? I would like a mechanical way to split the code into multiple files, which does not involve writing the type of all functions (preserve type inference).
In the meantime I found a solution (tested):
This is the initial situation (simplified to only have four functions, but in reality they are many more):
let rec f1 a b c =
f2 a b c;
f3 a b c;
f4 a b c;
and f2 a b c =
f1 a b c;
f3 a b c
f4 a b c
and f3 a b c =
f1 a b c;
f2 a b c
f4 a b c
and f4 a b c =
f1 a b c;
f2 a b c
f3 a b c
And here is the solution:
Suppose you decide to move f3 to another file. Then you can split the file above in two files as follows:
FILE 1
======
let callRef mf =
match !mf with
| None -> failwith "function ref is none"
| Some f -> f
let r_f3 = ref None;
let rec f1 a1 a2 a3 =
f2 a b c;
callRef r_f3 a1 b1 c1;
f4 a1 b1 c1;
and f2 a1 a2 a3 =
f1 a b c;
callRef r_f3 a1 b1 c1;
f4 a1 b1 c1;
and f4 a1 a2 a3 =
f1 a b c;
f2 a1 b1 c1;
callRef r_f3 a1 b1 c1;
FILE 2
======
let f3 a1 a2 a3 =
f1 a b c;
f2 a1 b1 c1;
f4 an bn cn;
Then, in the main initialization function (which is in a third file), you need to do
r_f3 := Some f3;
And that's it.
Repeat the same strategy to move f1, f2 and f4 out of the first file.
Update: This solution works well for functions which return unit, but unfortunately for functions which return an actual type it forces you to specify the function type explicitely, e.g.
let (r_f3 : (t1 -> t2 -> t3 -> t4 -> t5) option ref) = ref None;
or you can do this:
let (r_f3 : 'a option ref) = ref None;
but you'll get a compiler warning.

How to get a single value from a cell-range by matching multiple columns and rows

I'm struggling with this one.
Here is data from 'sheet1':
|| A B C D E
=========================================
1 || C1 C2 X1 X2 X3
.........................................
2 || a b 1 2 3
3 || a d 10 11 12
4 || c d 4 5 6
5 || c f 13 14 15
6 || e f 7 8 9
7 || e b 16 17 18
Here's data in "sheet2":
|| A B C D
=================================
1 || C1 C2 C3 | val
.................................
2 || a d X2 | ?
3 || c f X1 | ?
4 || e b X3 | ?
Note that column C in sheet2 actually has values equal to user column names in sheet1.
I simply want to match A, B and C in sheet2 with A, B and 1 in sheet1 to find values in the last column:
|| A B C D
=================================
1 || C1 C2 C3 | val
.................................
2 || a d X2 | 11
3 || c f X1 | 13
4 || e b X3 | 18
I've been playing with OFFSET() and MATCH() but can't seem to lock down on one cell using multiple search criteria. Can someone help please?
I would use this function in sheet2 D2 field:
=index(filter(sheet1!C:E,sheet1!A:A=A2,sheet1!B:B=B2),1,match(C2,sheet1!$C$1:$E$1,0))
Explanation:
There is a FILTER function which will result the X1,X2,X3 values (C,D,E columns of sheet1) of the row which matches to the these two conditions:
C1 is "a"
C2 is "d"
So it will give back an array: [10,11,12] - which is the values of the X1, X2, X3 (C,D,E ) columns of sheet1 in the appropriate row.
Then, the INDEX function will grab this array. Now we only need to determine which value to pick. The MATCH function will do this computation as it tries to find the third condition C3 (which is in this case "X2) in the header row of sheet1. And in this example it will give back "2" as X2 is in the 2nd position of sheet1!c1:e1
So the INDEX function will give back the 2nd element of this array:[10,11,12], which is 11, the desired value.
Hope this helps.

Resources