Link here to spreadsheet
As the title says, how can I end up with cells that don't match in value, the difference/complement (set theory)?
I would prefer it with only FUNCTIONS and no script.
{1,2,3,4}\{1,3} = {2, 4}
or with letters
{a,b,c,d}\{a,c} = {b, d}
or with with space.
{xyz zyx, abc cba, qwe ewq}\{xyz zyx, qwe ewq} = {abc cba}
You can add one single formula at the top of your result column like this :
=arrayformula(if(B2:B=A2:A,,A2:A))
Having two arrays:
Array1 Array2
1 1
2 b
b
4
c
you can get resulting array:
Result
2
4
c
Try this formula:
=FILTER(A2:A6,ROUND(MMULT(ArrayFormula(--(A2:A6<>TRANSPOSE(B2:B4))),TRANSPOSE(SPLIT(REPT(1/ROWS(B2:B4)&"/",Rows(B2:B4)),"/"))),5)=1)
May be too complex for this task, could somebody edit it? Please, look at sample sheet
Edit
I've found more simple way to do this, using Regular Expressions:
=FILTER(A2:A6,REGEXMATCH(ARRAYFORMULA("'"&A2:A6),JOIN("|",B2:B3))=false)
Related
I'm trying to calculate a Win/Loss formula based on two other cells but it wont work correctly. I attached what I currently have and I do not understand why it wont work.
For betting, I bet on the over (the o in o2.5) 2.5 so if the result is 4, it wins, and should say W. But incorrectly says L.
Any suggestions on how to get this to work?
Thank you in advance!
Google Sheets Screenshot
You just have a little mistake. What the screenshot shows is the following.
A
B
C
1
Bet line
Result
W/L
2
o2.5
4
L
3
o2.5
1
L
A and B were columns filled with data. Let me firstly mention that the data collection is a bit weird and your over and under would be better just initially be put in an extra column.
In cell C2, the code used was:
=IF(B2>RIGHT(A2,3), "W", "L")
The problem here is that column A now is in a text/string format due to the "o". Your IF() comparison now compares a float (number) to text (string) and it was apparently arbitrarily designated that the float is smaller. I reversed the order of the input and it will actually give the opposite result.
You just have to convert your string to a float, done by the VALUE() function.
=IF(B2>VALUE(RIGHT(A2,3)), "W", "L")
This correctly gives:
A
B
C
1
Bet line
Result
W/L
2
o2.5
4
W
3
o2.5
1
L
Good luck with your Gsheets adventure!
I have the following google sheet where:
Col a= quantities
Col b= product codes, which i´ve split between C and H.
I want to know the quantity according to different "filters"... this filters are the fields between C11 and H11, and they are optional. There are 6 possible filters.
It works using =QUERY formula located in H12 and it returns the sum of quantity values where the filters match...
BUT there´s the possibility of leaving a filter empty to get "all"...
the query is as follows:
=QUERY(A1:H7, "select sum(A) where C contains '"&C11&"' and lower(D) contains lower('"&D11&"') and E contains '"&E11&"' and lower(F) contains lower('"&F11&"') and lower(G) contains lower('"&G11&"') and lower(H) contains lower('"&H11&"') ",-1)
My problem is with the match type: where C contains '"&C11&"' and...
instead of using "contains" it should compare using "matches". this way it would count like it should, but then it won´t accept empty filters.
How can I get it to count only if the field is filled??
What´s wrong with the filter right now? It´s counting "4" matches because model matches "1" happens when model is 1 or 21, also with column D where i´m looking for value X and is also counting value XN as it contains "X". if formula is changed to "matches" instead of "contains", it won´t allow me to leave it blank.
Thank you!
Karl_S formula is great, but it does not sum the quantities in column A. Adapting his approach to SUMIFS seems to do it:
=SUMIFS(A2:A7,C2:C7, IF(ISBLANK(C11), "<>" ,C11),D2:D7, IF(ISBLANK(D11), "<>" ,D11),E2:E7, IF(ISBLANK(E11), "<>" ,E11),F2:F7, IF(ISBLANK(F11), "<>" ,F11),G2:G7, IF(ISBLANK(G11), "<>" ,G11),H2:H7, IF(ISBLANK(H11), "<>" ,H11))
Use this formula instead:
=COUNTIFS(C2:C7, IF(ISBLANK(C11), "<>" ,C11), D2:D7, IF(ISBLANK(D11), "*",D11), E2:E7, IF(ISBLANK(E11), "<>",E11), F2:F7, IF(ISBLANK(F11), "*",F11), G2:G7, IF(ISBLANK(G11), "*",G11), H2:H7, IF(ISBLANK(H11), "*",H11))
If one of the options is blank, it will match all items in that column. Otherwise it should do an exact match.
Suppose I've got a text values column (named Data), generated by =unique() function. Also, there is an array of patterns to find and replace for (Find and Replace columns).
Which formula should I use to scan each cell in Data for multiple patterns in Find and replace it, if match?
Data Find Replace Result
1 a c z a
2 b f y b
3 c e x z
4 d d
5 e x
6 c z
Tried =SUBSTITUTE() and =IF() functions, but it fails, when I set an array of patterns, instead of single one.
If the table you is in range A1:E7, try this formula
=TRANSPOSE(SPLIT(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(ARRAYFORMULA(CONCATENATE($B$2:$B$7&"|")),$C$2,$D$2),$C$3,$D$3),$C$4,$D$4),"|"))
You can read further about this in an older post and google docs forum.
Array solution
This formula takes range to replace, so it can be used for variable number of patterns:
=QUERY(ARRAYFORMULA({REGEXMATCH(A2,$B$2:$B$4),
REGEXREPLACE(A2,$B$2:$B$4,$C$2:$C$4)}),
"select Col2 order by Col1 desc limit 1")
or this one:
=INDEX(ArrayFormula(REGEXREPLACE(A2,$B$2:$B$4,$C$2:$C$4)),IFERROR(MATCH(A2,$B$2:$B$4,0),1))
or this:
=IFERROR(INDEX($C$2:$C$4,MATCH(A2,$B$2:$B$4,0)),A2)
The formula is need to be dragged down.
Single Formula & Array solution
Also this single ArrayFormula will do the trick:
=ArrayFormula(trim(transpose(query({IF(--REGEXMATCH(TRANSPOSE(A2:A7),$B$2:$B$4)=1,
REGEXREPLACE(TRANSPOSE(A2:A7),$B$2:$B$4,$C$2:$C$4),"");
TRANSPOSE(if(--not(REGEXMATCH(A2:A7,JOIN("|",B2:B4))),A2:A7,""))},,COUNTA(A2:A)))))
or this shorter formula:
=ArrayFormula(IFERROR(VLOOKUP(MATCH(A2:A7,B2:B4,0),{ROW(INDIRECT("a1:a"&COUNTA(C2:C4))),C2:C4},2,0),A2:A7))
Please, see explanations in Sample file
I have a table like so:
A B C D
1 3 2 1
2 3 2 1
3 0 2 2
I want to vlookup the first column so that it returns the 3 columns after.
For example if I look up 2, i want the return to be 3 2 1.
i need it in one formula because it will go into a sumproduct expression.
Does not have to be a vlookup. I just need something that will return me an array though some type of indexing or lookup.
One of the ways to achieve this is query. So for the data given by you (A, B, C are column), you can use the following formula to get all three columns for the lookup value 2
=QUERY($A$1:$D$3,"select B,C,D where A = 2")
Then you can apply any aggregate function on top of this too. For eg:
=sum(QUERY($A$1:$D$3,"select B,C,D where A = 1"))
Check this link
Given a spreadsheet with two columns, say A and B, each containing n values under it, all text; is there a formula that allows me to fill just one cell containing the amount of equal values in columns A and B?
Example:
A B
-----
1 M M
2 L M
3 L L
4 M M
5 M L
-----
3
Since columns A and B both contain an M in rows 1 and 4, and an L in row 3, the result is (i.e. 2+1).
A simple solution is to use QUERY function in google spreadsheet:
=SUM(QUERY(A1:B5, "Select 1 where A = B"))
Or using SUMPRODUCT:
=ARRAYFORMULA(SUM(((A:A)=(B:B)) * (1) ))
One of possible solution will be to add the following formula in column C: =N(EXACT(A1,B1)),
copy it throughout the column down to the last row and then sum up the column C values using =SUM(C1:C5).
Here we go:
=IF(EQ(LEFT(A0, 1), "A"),
SUM(ARRAYFORMULA(N(EXACT(TRANSPOSE(A1:A5), TRANSPOSE(B1:B5))))),
"")
Reading: if the value in row 0 (it doesn't exist, but my example above does ;) ) is equal to the text "A", take the sum of an array N, otherwise put in an empty string. ("")
Array N is build by taking the transpose of columns A and B. (Turning them, so they look like a row) and comparing the values. (Burnash gave me the options "N" and "EXACT") The formula N transforms this into a 1 or 0.
Copy paste the formula in an entire row and what do you know... It worked! That was hellish for something so trivial.
Thanks anyway.