Search Data for matching row/array - google-sheets

I want to search a set of data to see if it contains a matching set of values eg.
+------+------+------+------+
| Col1 | Col2 | Col3 | Col4 |
+------+------+------+------+
| A | B | C | D |
+------+------+------+------+
would match the last row in
+------+------+------+------+
| Col1 | Col2 | Col3 | Col4 |
+------+------+------+------+
| B | C | D | A |
| A | D | B | C |
| A | B | B | D |
| D | C | B | A |
| A | B | C | D |
+------+------+------+------+
A boolean return would be fine.
Any pointers would be greatly appreciated.
Cheers

Assumptions
Columns to check: A:D
Values to check are in F1:I1
Result in K1 - boolean
Code
=NOT(ISERROR(
QUERY({ArrayFormula(A1:A&B1:B&C1:C&D1:D)},
"select * where Col1='"&JOIN("",F1:I1)&"'",0)
)
)
Picture

Related

Conditionally CONCAT based on helper column data using ARRAYFORMULA in Google Sheets

I have 2 columns of names (Name 1, Name 2) which I would like to concat into a single column.
[CURRENT DATA SET] [FORMULA - CONCAT]
| A | B | | D |
| Name1 | Name2 | | Name1_Name2 |
| Name3 | Name4 | | Name3_Name4 |
| Name5 | Name6 | | Name5_Name6 |
This portion is working using my ARRAYFORMULA:
=ARRAYFORMULA(
IF(
ISBLANK(B4:B),
CONCAT(A4:A,B4:B),
CONCAT(A4:A,("_"&B4:B))
)
)
Here is the issue: Sometimes I need the CONCAT formula to put column B first, then Colum A (Example Name2_Name1).
Objective: The CONCAT formula needs to be conditional based on a helper column containing the list of valid name options.
Logic:
If helper column matches CONCAT, CONCAT ColumnA_ColumnB.
If helper column does not match CONCAT, ColumnB_ColumnA.
If still does not match, leave blank.
Expected Results using a helper column
[CURRENT DATA SET] [Helper Column] [EXPECTED RESULTS]
| A | B | | C | | D |
| Name1 | Name2 | | Name1_Name2 | | Name1_Name2 |
| Name3 | Name4 | | Name6_Name5 | | Name3_Name4 |
| Name5 | Name6 | | Name3_Name4 | | Name6_Name5 |
| Name7 | | | Name5 | | |
| Name5 | | | Name8 | | Name5 |
Is it possible to create an arrayformula to achieve these expected results?
Here is my Google Sheet: Click Here
See if this works for you:
=ArrayFormula(IFERROR(IFERROR(VLOOKUP(A4:A&IF(LEN(B4:B), "_"&B4:B,), D4:D, 1, 0), VLOOKUP(IF(LEN(B4:B), B4:B&"_",)&A4:A, D4:D, 1, 0))))

How to combine 2 queries result in single query from Google Sheets

I would like to combine 2 result in one, to make them display in 2 column
what I have:
+------------+------------+------------+------------+------------+------------+------------+
| B | C | D | E | F | G | H |
+------------+------------+------------+------------+------------+------------+------------+
| Supplier A | 40ft | 19-0201 | 02/09/2019 | 05/09/2019 | 05/09/2019 | $2,590.60 |
| Supplier B | 20ft | 19-0206 | 04/09/2019 | 06/09/2019 | 07/09/2019 | $7,198.10 |
| Supplier C | 40ft | 19-0208 | 04/09/2019 | 06/09/2019 | 07/09/2019 | $3,673.40 |
| Supplier B | 20ft | 19-0207 | 04/09/2019 | 07/09/2019 | 08/09/2019 | $5,592.20 |
| Supplier C | 20ft | 19-0203 | 06/09/2019 | 05/09/2019 | 06/09/2019 | $863.30 |
| Supplier B | 20ft | 19-0204 | 05/09/2019 | 05/09/2019 | 06/09/2019 | $4,190.20 |
| Supplier D | 28ft | 19-0205 | 05/09/2019 | 07/09/2019 | 08/09/2019 | $1,390.60 |
| Supplier E | 14ft | 19-0209 | 07/09/2019 | 09/09/2019 | 09/09/2019 | $180.30 |
| Supplier B | 10ft | 19-0211 | 08/09/2019 | 08/09/2019 | 09/09/2019 | $12,392.80 |
| Supplier C | 40ft | 19-0210 | 07/09/2019 | 10/09/2019 | 11/09/2019 | $6,591.30 |
| Supplier B | 20ft | 19-0202 | 03/09/2019 | 12/09/2019 | 13/09/2019 | $1,380.50 |
| Supplier F | 14ft | 19-0213 | 09/09/2019 | 12/09/2019 | 12/09/2019 | $4,576.30 |
this is first query code :
=ARRAYFORMULA(TEXTJOIN(CHAR(10),TRUE,SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(QUERY(B16:H34,"SELECT B, D, SUM(H) GROUP BY B, D ORDER BY B ASC LABEL SUM(H)'' FORMAT SUM(H) '$##,##0.00' ")),,COLUMNS(QUERY(B16:H34,"SELECT B, D, SUM(H) GROUP BY B, D ORDER BY B ASC LABEL SUM(H)'' FORMAT SUM(H) '$##,##0.00' ")))))," → "," → ")))&CHAR(10)&CHAR(10)&"Total Costing : "&TEXT(SUM(H16:H34),"$0,000.00")
+-----------------------------------+
| Supplier A 19-0201 $2,590.60 |
| Supplier B 19-0202 $1,380.50 |
| Supplier B 19-0204 $4,190.20 |
| Supplier B 19-0206 $7,198.10 |
| Supplier B 19-0207 $5,592.20 |
| Supplier B 19-0211 $12,392.80 |
| Supplier C 19-0203 $863.30 |
| Supplier C 19-0208 $3,673.40 |
| Supplier C 19-0210 $6,591.30 |
| Supplier D 19-0205 $1,390.60 |
| Supplier E 19-0209 $180.30 |
| Supplier F 19-0213 $4,576.30 |
| |
| Total Costing $50,618.60 |
and my second query code :
={QUERY({B16:H34},"SELECT Col1, SUM(Col7)/"& SUM(H16:H34)&" WHERE Col1 IS NOT NULL GROUP BY Col1 LABEL SUM(Col7)/"& SUM(H16:H34)&"'Scale Of Amount' FORMAT SUM(Col7)/"& SUM(H16:H34)&"'(0.00%)'");"Total Costing Scale","(100%)"}
+---------------+--------------+
| | SUM of Amount|
+---------------+--------------+
| Supplier A | (5.12%) |
| Supplier B | (60.75%) |
| Supplier C | (21.98%) |
| Supplier D | (2.75%) |
| Supplier E | (0.36%) |
| Supplier F | (9.04%) |
| Total Costing | (100.00%) |
How to make it show :
+-------------------------+-------------------------+
| | SUM of Amount |
+-------------------------+-------------------------+
| Supplier A 19-0201 | $2,590.60 (5.12%) |
| Supplier B 19-0202 | $1,380.50 |
| Supplier B 19-0204 | $4,190.20 |
| Supplier B 19-0206 | $7,198.10 |
| Supplier B 19-0207 | $5,592.20 |
| Supplier B 19-0211 | $12,392.80 (60.75%) |
| Supplier C 19-0203 | $863.30 |
| Supplier C 19-0208 | $3,673.40 |
| Supplier C 19-0210 | $6,591.30 (21.98%) |
| Supplier D 19-0205 | $1,390.60 (2.75%) |
| Supplier E 19-0209 | $180.30 (0.36%) |
| Supplier F 19-0213 | $4,576.30 (9.04%) |
| | |
| Total Costing | $50,618.60 (100.00%) |
This the formula that can be used:
=arrayformula({query( sort ( unique({B2:B,D2:D,sumif(B2:B&":"&D2:D,"=" &
B2:B&":"&D2:D,H2:H)}),1,true,2,true),"Select * where Col1 is not null"),
iferror(vlookup(transpose(split(join(",",rept("0,",query(filter(B2:B,B2:B<>""),
"Select Count(Col1) group by Col1 label Count(Col1) ''")-1) &
sequence(counta(unique(B2:B)))),",",true,false)),
{sequence(counta(unique(B2:B))),
query( unique({B2:B,sumif(B2:B,"="&B2:B,H2:H)/sum(H2:H)}),
"Select Col1, Col2 where Col1 is not null")},3,false),"");
{"Total","",sum(filter(H2:H,H2:H<>"")),1}})
Update 1:
= arrayformula
(
{
query (sort (unique({B2:B,D2:D,sumif(B2:B&":"&D2:D,"=" & B2:B&":"&D2:D,H2:H)}),1,true,2,true),"Select * where Col1 is not null"),
iferror (
vlookup(transpose(split(join(",",
rept
(
"0,",query(unique(filter({B2:B,B2:B&":"&D2:D},B2:B<>"")),"Select Count(Col1) group by Col1 label Count(Col1) ''")-1
) & sequence (counta(unique(B2:B)))),",",true,false)),
{
sequence(counta(unique(B2:B))),
query (unique ({B2:B,sumif(B2:B,"="&B2:B,H2:H)/sum(H2:H)}),"Select Col1, Col2 where Col1 is not null")
},3,false
),""
) ; {"Total","",sum(filter(H2:H,H2:H<>"")),1}
}
)

How to count a value from a cell which contains multiple values?

I have a table with cells which contain comma-separated multiple values as follows:
+----------+
| Column A |
|----------|
| a, b |
|----------|
| a, b, d |
|----------|
| b, c |
|----------|
| c, d, e |
+----------+
I would like to get a table which counts the number of a, b, ..., e as follows:
+-----------------------+
| Column A | Column B |
|-----------------------|
| a | 2 |
|-----------------------|
| b | 3 |
|-----------------------|
| c | 2 |
|-----------------------|
| d | 2 |
|-----------------------|
| e | 1 |
+-----------------------+
Is there any Google Sheets or LibreOffice Calc spreadsheet formula to do this?
C1: =UNIQUE(TRANSPOSE(SPLIT(TEXTJOIN(" ,",1,A:A)," ,")))
D1: =ARRAYFORMULA(IF(LEN(C:C),COUNTIF(A:A,"=*"&C:C&"*"),))
=QUERY(TRANSPOSE(SPLIT(TEXTJOIN(" ,",1,A:A)," ,")),
"select Col1, count(Col1)
where Col1 is not null
group by Col1
label count(Col1) ''")
={UNIQUE(TRANSPOSE(SPLIT(TEXTJOIN(" ,",1,A:A)," ,"))),
ARRAYFORMULA(IF(LEN(UNIQUE(TRANSPOSE(SPLIT(TEXTJOIN(" ,",1,A:A)," ,")))),
COUNTIF(A:A,"=*"&UNIQUE(TRANSPOSE(SPLIT(TEXTJOIN(" ,",1,A:A)," ,")))&"*"),))}

Compare each cell in two rows, but with an exception

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

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)?

Resources