Join Tables NxN in google sheets [duplicate] - google-sheets

This question already has answers here:
Generate all possible combinations for Columns(cross join or Cartesian product)
(5 answers)
Closed 1 year ago.
I have 2 tables (matrixes) for instance
a
b
c
and
x
y
z
I would like to the final result to be
a x
a y
a z
b x
b y
b z
c x
c y
c z
How can it be possible

Desired output is unclear whether it is in a single or separate columns, so I'll provide both outcomes:
Single column (C1):
=INDEX(FLATTEN(FILTER(A:A, A:A<>"")&" "&TRANSPOSE(FILTER(B:B, B:B<>""))))
Separate columns (D1):
=INDEX(SPLIT(FLATTEN(FILTER(A:A, A:A<>"")&" "&TRANSPOSE(FILTER(B:B, B:B<>""))), " "))
Output:

Related

Check if a value is duplicate in a group of values in Google Sheets

I have a table where I have many rows with their ids in groups of 2, and another column with one value associated that can be there ("X" value) or not:
ID
Flag_value
A
X
A
B
X
B
C
C
X
D
X
D
X
What I want to do is to check if there are any cases where the X value is associated to the same ID twice. In this case, this only happens for D (both of the ids have an "X"), but not for A,B or C. Having a lot of rows, is there a way of doing this with a formula? Many thanks in advance!
You may try:
=unique(filter(A2:A;map(A2:A;lambda(z;countifs(B2:B;"X";A2:A;z)))>1))

How to create a long run program [duplicate]

This question already has answers here:
Google Sheets - How to count streaks of non-zero numbers on one column
(2 answers)
Closed 2 months ago.
I'm trying to create a formula, likely used in Google Sheets, that will count the number of consecutive "hits" forward from the first recorded event and then another that will count in reverse from the last recorded event.
Example
X X X X X X X X O X
In this example, the consecutive hits forward would be "8" and the consecutive hits in reverse would be "1"
I have been unsuccessful in coming up with a formula
try:
=LEN(SPLIT(SUBSTITUTE(A1, " ", ), "O"))
and
=INDEX(LEN(SPLIT(SUBSTITUTE(A1, " ", ), "O")),,COLUMNS(SPLIT(A1, "O")))

How to count the number of values that appear only once (and more than once) in a column in Google Sheets?

Lets say I have the following column A:
X
Y
X
Z
W
Z
W
I want to write 2 formulae, one that counts the number of values that appear exactly once, and one that counts the number of values that appear more than once. So for the above column, the results would be 1 (only Y) and 3 (W, X, Z).
I tried the following formula, but got an error:
=FILTER(A:A,COUNTIF(A:A,A:A)>1)
How can I do this using Google Sheets? Please note, some column values may be empty and should be ignored.
only once:
=FILTER(A:A, COUNTIF(A:A, A:A)=1)
more than once:
=UNIQUE(FILTER(A:A, COUNTIF(A:A, A:A)>1))

Google Spreadsheet - compare cells on same row and get number of matches?

I have values in column A, B and C for Google Spreadsheet:
A contains the results of each match (1X2)
B is what person B guessed that match
C is what person C guessed
Players can for each match guess 1 (home win), x (equal), 2 (away win) or a combination of them, like x2.
How can I compare the player's guesses (column B and C) with the match result (column A) and get the number of correct answers/matches?
Example:
Person B scores three points, because he guessed three matches correctly (not the second match though).
A B C
1 1x x2
x 1 x
2 2 1x
x 1x 2
CORRECT: 3 1
Add 2 columns D and E, than represent either a 0 or 1, then sum columns D & E. You would then put:
D2=IF(A2=B2,1,0)
E2=IF(A2=C2,1,0)
Then just copy paste formulas - since you aren't using absolute $ syntax for rows 3,4,5 etc.
Then just have D1=SUM(D2:D99) E1=SUM(E2:E99) - or something to that effect depending on number of rows.

Spreadsheet function to sum all values in one column based on criteria from another column

I want a spreadsheet function that will produce a sum of all values in column B for when column A is equal to X and when it is equal to Y.
A B
X 10
Y 3
X 7
X 22
Y 4
Y 9
The output should look like the following (where 39 and 16 are the results of the formulas):
X 39 -> 10 + 7 + 22
Y 16 -> 3 + 4 + 9
Something like this
X 10
Y 3
X 7
X 22
Y 4
Y 9
X "=SUMIF(A1:A6;A8;B1:B6)"
Y "=SUMIF(A1:A6;A9;B1:B6)"
use SUMIF(range, criteria, sum_range): (sum values between B2-B8, using value in A2-A8 as criterea, using the specified condition)
=SUMIF(A2:A8,"=X",B2:B8)
=SUMIF(A2:A8,"=Y",B2:B8)
You can use SUMPRODUCT to calculate the totals. For the "X" values:
=SUMPRODUCT((A1:A6="X")*(B1:B6))
for the "Y" values:
=SUMPRODUCT((A1:A6="Y")*(B1:B6))
Hope that helps,
Eric Melski
EDIT: Apparently you must use ARRAYFORMULA to use SUMPRODUCT in Google's spreadsheet. See for example http://www.google.com/support/forum/p/Google+Docs/thread?tid=13a3eb824446e891&hl=en
One quick and dirty solution is to make two new columns. For each row x, Cx should be something like =Ax=='X'?Bx:0. Do the same for column D, but checking Ax=='Y'. Then sum C and D.
(Not sure if that matches Google Spreadsheet syntax exactly.)
What about
=query(A:B, "select A, sum(B) group by A order by sum(B) desc")
The fact that Google Docs doesn't support the sumproduct and the -- operator, as Excel does, is a bit bothering. You could always replicate the functionality using more columns, but as you responded in one of your comments, this seems impossible.
You could check if a hidden column is rendered in the form. If it is not, this is the way to go.

Resources