Compare each cell in two rows, but with an exception - google-sheets

I have a table that keeps track of scores from a test. It compares the row with someone's answers to the row with the correct data:
A B C D E
+--------------+-----+-----+-----+-------+
1 | | Q1 | Q2 | Q3 | Score |
+--------------+-----+-----+-----+-------+
2 | Answers | C | B | A | |
+--------------+-----+-----+-----+-------+
3 | George | C | A | B | 1 |
4 | Judith | C | C | A | 2 |
5 | James | A | B | C | 1 |
+--------------+-----+-----+-----+-------+
The formula behind the Score column is:
=arrayformula(sumproduct(($B$2:$D$2=B3:D3)))
The first part of sumproduct is a static reference to the Answers row. The second part is comparing it against the row it's on. However I want to add an exception: if the Answers row contains an asterisk it should consider all answers correct:
A B C D E
+--------------+-----+-----+-----+-------+
1 | | Q1 | Q2 | Q3 | Score |
+--------------+-----+-----+-----+-------+
2 | Answers | C | * | A | |
+--------------+-----+-----+-----+-------+
3 | George | C | A | B | 2 |
4 | Judith | C | C | A | 3 |
5 | James | A | B | C | 1 |
+--------------+-----+-----+-----+-------+
How would I be able to do this?

Please try:
=arrayformula(sumproduct(($B$2:$D$2=B3:D3)+($B$2:$D$2="*")))

=IF(OR($B$2=B3, $B$2="*"), 1, )+
IF(OR($C$2=C3, $C$2="*"), 1, )+
IF(OR($D$2=D3, $D$2="*"), 1, )
this will cover up to 51 questions (columns / range of B:AZ)
=IF(LEN($B$2),IF(OR($B$2=B3,$B$2="*"),1,),)+
IF(LEN($C$2),IF(OR($C$2=C3,$C$2="*"),1,),)+
IF(LEN($D$2),IF(OR($D$2=D3,$D$2="*"),1,),)+
IF(LEN($E$2),IF(OR($E$2=E3,$E$2="*"),1,),)+
IF(LEN($F$2),IF(OR($F$2=F3,$F$2="*"),1,),)+
IF(LEN($G$2),IF(OR($G$2=G3,$G$2="*"),1,),)+
IF(LEN($H$2),IF(OR($H$2=H3,$H$2="*"),1,),)+
IF(LEN($I$2),IF(OR($I$2=I3,$I$2="*"),1,),)+
IF(LEN($J$2),IF(OR($J$2=J3,$J$2="*"),1,),)+
IF(LEN($K$2),IF(OR($K$2=K3,$K$2="*"),1,),)+
IF(LEN($L$2),IF(OR($L$2=L3,$L$2="*"),1,),)+
IF(LEN($M$2),IF(OR($M$2=M3,$M$2="*"),1,),)+
IF(LEN($N$2),IF(OR($N$2=N3,$N$2="*"),1,),)+
IF(LEN($O$2),IF(OR($O$2=O3,$O$2="*"),1,),)+
IF(LEN($P$2),IF(OR($P$2=P3,$P$2="*"),1,),)+
IF(LEN($Q$2),IF(OR($Q$2=Q3,$Q$2="*"),1,),)+
IF(LEN($R$2),IF(OR($R$2=R3,$R$2="*"),1,),)+
IF(LEN($S$2),IF(OR($S$2=S3,$S$2="*"),1,),)+
IF(LEN($T$2),IF(OR($T$2=T3,$T$2="*"),1,),)+
IF(LEN($U$2),IF(OR($U$2=U3,$U$2="*"),1,),)+
IF(LEN($V$2),IF(OR($V$2=V3,$V$2="*"),1,),)+
IF(LEN($W$2),IF(OR($W$2=W3,$W$2="*"),1,),)+
IF(LEN($X$2),IF(OR($X$2=X3,$X$2="*"),1,),)+
IF(LEN($Y$2),IF(OR($Y$2=Y3,$Y$2="*"),1,),)+
IF(LEN($Z$2),IF(OR($Z$2=Z3,$Z$2="*"),1,),)+
IF(LEN($AA$2),IF(OR($AA$2=AA3,$AA$2="*"),1,),)+
IF(LEN($AB$2),IF(OR($AB$2=AB3,$AB$2="*"),1,),)+
IF(LEN($AC$2),IF(OR($AC$2=AC3,$AC$2="*"),1,),)+
IF(LEN($AD$2),IF(OR($AD$2=AD3,$AD$2="*"),1,),)+
IF(LEN($AE$2),IF(OR($AE$2=AE3,$AE$2="*"),1,),)+
IF(LEN($AF$2),IF(OR($AF$2=AF3,$AF$2="*"),1,),)+
IF(LEN($AG$2),IF(OR($AG$2=AG3,$AG$2="*"),1,),)+
IF(LEN($AH$2),IF(OR($AH$2=AH3,$AH$2="*"),1,),)+
IF(LEN($AI$2),IF(OR($AI$2=AI3,$AI$2="*"),1,),)+
IF(LEN($AJ$2),IF(OR($AJ$2=AJ3,$AJ$2="*"),1,),)+
IF(LEN($AK$2),IF(OR($AK$2=AK3,$AK$2="*"),1,),)+
IF(LEN($AL$2),IF(OR($AL$2=AL3,$AL$2="*"),1,),)+
IF(LEN($AM$2),IF(OR($AM$2=AM3,$AM$2="*"),1,),)+
IF(LEN($AN$2),IF(OR($AN$2=AN3,$AN$2="*"),1,),)+
IF(LEN($AO$2),IF(OR($AO$2=AO3,$AO$2="*"),1,),)+
IF(LEN($AP$2),IF(OR($AP$2=AP3,$AP$2="*"),1,),)+
IF(LEN($AQ$2),IF(OR($AQ$2=AQ3,$AQ$2="*"),1,),)+
IF(LEN($AR$2),IF(OR($AR$2=AR3,$AR$2="*"),1,),)+
IF(LEN($AS$2),IF(OR($AS$2=AS3,$AS$2="*"),1,),)+
IF(LEN($AT$2),IF(OR($AT$2=AT3,$AT$2="*"),1,),)+
IF(LEN($AU$2),IF(OR($AU$2=AU3,$AU$2="*"),1,),)+
IF(LEN($AV$2),IF(OR($AV$2=AV3,$AV$2="*"),1,),)+
IF(LEN($AW$2),IF(OR($AW$2=AW3,$AW$2="*"),1,),)+
IF(LEN($AX$2),IF(OR($AX$2=AX3,$AX$2="*"),1,),)+
IF(LEN($AY$2),IF(OR($AY$2=AY3,$AY$2="*"),1,),)+
IF(LEN($AZ$2),IF(OR($AZ$2=AZ3,$AZ$2="*"),1,),)
and here is "Formula Generator" sheet for that

Related

Google SpreadSheet Query - Merge queries results into one

Let's take this data in a Google sheet:
| Product | Green | Red | Date |
| A | 1 | 0 | 1/1/2020 |
| A | 1 | 0 | 2/1/2020 |
| B | 0 | 1 | 2/25/2020 |
| C | 1 | 0 | 2/28/2020 |
| A | 0 | 1 | 3/1/2020 |
My goal would be to display the sum of Green / Red for each product:
From the beginning of the year,
For the current month.
I created this Google Query to get the results for all the year:
=QUERY(DATA!A:D,"select A, sum(B), sum(C) where D >= date '2020-01-01' and D <= date '2020-12-31' group by A")
I get this result:
| Product | sum Green | sum Red |
| A | 2 | 1 |
| B | 0 | 1 |
| C | 1 | 0 |
And this query for the given month (I simplified the query, but I have a Settings sheet to specify the month to query):
=QUERY(DATA!A:D,"select A, sum(B), sum(C) where D >= date '2020-01-01' and D <= date '2020-01-31' group by A")
And get this result:
| Product | sum Green | sum Red |
| A | 1 | 0 |
Now I'm stuck in joining the two results into one, like this:
| Product | Year sum Green | Year sum Red | Jan sum Green | Jan sum Red |
| A | 2 | 1 | 1 | 0 |
| B | 0 | 1 | | |
| C | 1 | 0 | | |
How can I achieve this ?
Thanks a lot for your help!
try:
=ARRAYFORMULA(IFNA(VLOOKUP(F2:F, QUERY(DATA!A:D,
"select A,sum(B),sum(C)
where month(D)+1 = 1
group by A
label sum(B)'Jan sum Green',sum(C)'Jan sum Red'"), {2,3}, 0)))

PSQL code missing

My problem on getting one row shown with two null values.
FROM tuotemerkki;
tmtunnus | tmnimi | maa
----------+----------+-------------
1 | McCee | Yhdysvallat
2 | KooTek | Italia
3 | Giardino | Italia
(3 rows)
FROM tuote;
ttunnus | tnimi | kuvaus | suositushinta | tmtunnus
---------+-----------------------+--------------------+---------------+----------
111 | Trimmeri TRCee | tehokas 4-tahtinen | 179.00 | 1
112 | Trimmerisiima Cee | laadukas siima | 6.99 | 1
113 | Moottorisaha MSCee RR | robusti ja raskas | 559.00 | 1
114 | Trimmerisiima Y | yleissiima | 3.99 | 2
115 | Lapio L | kevyt yleislapio | 23.95 | 2
(5 rows)
I need to get this selected with the NULL VALUE on giardino from tmnimi.
tmnimi | tnimi | kuvaus
----------+-----------------------+--------------------
McCee | Trimmeri TRCee | tehokas 4-tahtinen
McCee | Trimmerisiima Cee | laadukas siima
McCee | Moottorisaha MSCee RR | robusti ja raskas
KooTek | Trimmerisiima Y | yleissiima
KooTek | Lapio L | kevyt yleislapio
Giardino | |
(6 rows)
I get only this selected
SELECT tmnimi, tnimi, kuvaus
FROM tuote
CROSS JOIN tuotemerkki
WHERE tuote.tmtunnus = tuotemerkki.tmtunnus;
tmnimi | tnimi | kuvaus
--------+-----------------------+--------------------
McCee | Trimmeri TRCee | tehokas 4-tahtinen
McCee | Trimmerisiima Cee | laadukas siima
McCee | Moottorisaha MSCee RR | robusti ja raskas
KooTek | Trimmerisiima Y | yleissiima
KooTek | Lapio L | kevyt yleislapio
(5 rows)
Use a left join between the two tables:
SELECT
t1.tmnimi,
t2.tnimi,
t2.kuvaus
FROM tuotemerkki t1
LEFT JOIN tuote t2
ON t1.tmtunnus = t2.tmtunnus
When you left join from tuotemerkki to tuote, then every record in the former table is guaranteed to appear in the result set. Since the Giardino record does not match to anything in the tuote table, all the columns from that table would have a NULL value for the Giardino record.

Transpose or Pivot - neo4j collect()

how to transpose a n x m collection in the return statement ? OR before return statement based on a particular column?
example:
A | B | C
aa | 2 | 3
bb | 4 | 6
cc | 5 | 8
dd | 55| 9
To
aa | bb | cc | dd
2 | 4 | 5 | 55
3 | 6 | 8 | 9
Example:
with [{Label:'User',Lang:'English'},{Label:'Usuario',Lang:'Español'},{Label:'用户',Lang:'中文_简体'}] as t unwind t as p return
this returns
p.Label | p.Lang
User | English
Usuario | Español
用户 | 中文_简体
should be transposed to
User | Usuario | 用户
English | Español | 中文_简体
Well, MAYBE there is what you want in APOC.
CALL apoc.help(KEYWORD)
If not, you are good to write your own function
https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_user_defined_functions
Would extract help? This might get you part-way there:
neo4j> with [{Label:'User',Lang:'English'},{Label:'Usuario',Lang:'Español'},{Label:'用户',Lang:'中文_简体'}] as t return extract( i in t | i.Label), extract(i in t | i.Lang);
+--------------------------------------------------------------+
| extract( i in t | i.Label) | extract(i in t | i.Lang) |
+--------------------------------------------------------------+
| ["User", "Usuario", "用户"] | ["English", "Español", "中文_简体"] |
+--------------------------------------------------------------+

Joining two tables, A and B, where the column names of A should be joined with B based on the values of a column in B

The title is a little confusing, so here is an example of the problem I'm facing.
Table:
FORM_QUESTION
Fields:
student_id
q1_ans
q2_ans
q3_ans
q4_ans
q5_ans
x--------------x----------x----------x----------x----------x----------x
| student_id | q1_ans | q2_ans | q3_ans | q4_ans | q5_ans |
x--------------x----------x----------x----------x----------x----------x
| 1 | A | D | B | B | E |
| 2 | D | C | B | A | D |
| 3 | B | C | D | A | B |
x--------------x----------x----------x----------x----------x----------x
The FORM_QUESTION table stores a student's answers for each question.
Here is information on the second table:
Table:
FORM_VALID_ANS
Fields:
question_id
valid_answer
x---------------x----------------x
| question_id | valid_answer |
x---------------x----------------x
| q1_ans | A |
| q1_ans | B |
| q2_ans | A |
| q2_ans | B |
| q2_ans | C |
| q2_ans | D |
| q3_ans | A |
| q4_ans | A |
| q4_ans | B |
| q5_ans | A |
x---------------x----------------x
The second table, FORM_VALID_ANS, stores the valid, acceptable answers for a particular question. So, according to the above table, here is the acceptable list of values for each question:
q1_ans: A, B
q2_ans: A, B, C, D
q3_ans: A
q4_ans: A, B
q5_ans: A
As you can see, the values for the FORM_VALID_ANS.valid_answer include only the question field names for FORM_QUESTION ("q1_ans", "q2_ans", "q3_ans", "q4_ans", and "q5_ans"). I need to check each students' answer to make sure it is a valid value that they can enter, which is specified in the FORM_VALID_ANS.valid_answer field.
The desired output, where XXX represents an invalid value, and all other values would be answered value:
x--------------x----------x----------x----------x----------x----------x
| student_id | q1_ans | q2_ans | q3_ans | q4_ans | q5_ans |
x--------------x----------x----------x----------x----------x----------x
| 1 | A | D | XXX | B | XXX |
| 2 | XXX | C | XXX | A | XXX |
| 3 | B | C | XXX | A | XXX |
x--------------x----------x----------x----------x----------x----------x
Is it possible to join these two tables together and produce these results (or similar results)?

URL BNF search part does not make sense

While implementing a Java regular expression for URL based on the URL BNF published by W3C, I've failed to understand the search part. As quoted:
httpaddress h t t p : / / hostport [ / path ] [ ?
search ]
search xalphas [ + search ]
xalphas xalpha [ xalphas ]
xalpha alpha | digit | safe | extra | escape
alpha a | b | c | d | e | f | g | h | i | j | k |
l | m | n | o | p | q | r | s | t | u | v |
w | x | y | z | A | B | C | D | E | F | G |
H | I | J | K | L | M | N | O | P | Q | R |
digit 0 |1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
safe $ | - | _ | # | . | & | + | -
extra ! | * | " | ' | ( | ) | ,
Search claims it is xalphas seperated by a plus sign.
xalphas can contain plus signs by it self, as claimed by safe.
Thus according to my understanding , it should be:
search xalphas
Where am I wrong here?
That's pretty clearly a mistake (+ is a reserved delimiter for URIs), but the BNF you're linking to seems to be out of date. Probably best to use the one included at the end of the latest RFC 3986.

Resources