Column not containing in range - google-sheets

So I've been struggling with this one query:
Column A
--
usa-persona
ind-personb
kor-personc
jpn-persond
Column B
--
usa-persona
ind-personb
ind-personb2
ind-personb3
Desired Output
--
ind-personb2
ind-personb3
Search through column B,
Return ones that have the string 'ind',
But they should not be in Column A.
This is what I have, which doesn't seem to do the last part (checking to see if they are in Column A).
QUERY(A:B, "SELECT B where B contains 'ind' and not B matches '"&A:A&"'"))
How do I go about this?

Use filter(), like this:
=filter( B2:B, search("ind", B2:B), isna(match(B2:B, A2:A, 0)) )

use:
=FILTER(B1:B; NOT(COUNTIF(A1:A; B1:B)))

Related

What aggregation function to concatenate string like sum() for number in google sheet?

Basically I would like to convert the following table
Name
Team
A
X
B
X
A
Y
B
Z
C
X
A
Z
to
Name
Team
A
X,Y,Z
B
X,Z
C
X
It is something like sum(B) group by A but for strings rather than numbers
What kind of Google Sheet formula or Query() can do this? Thanks!
=ArrayFormula(
REGEXREPLACE(
SPLIT(
TRANSPOSE(
QUERY(
QUERY(
SPLIT(
FILTER(A2:A&"♦♥"&B2:B,A2:A<>"")&",",
"♥"
),
"SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1",0
),,10^7
)
),
"♦"
),
"^(?:,?\s*)+|(?:,\s*)$|(,)\s*(?:,\s*)*","$1"
)
)
Use this formula-
={UNIQUE(A2:INDEX(A2:A,COUNTA(A2:A))),BYROW(UNIQUE(A2:INDEX(A2:A,COUNTA(A2:A))),LAMBDA(x,JOIN(",",FILTER(B2:B,A2:A=x))))}
Here A2:INDEX(A2:A,COUNTA(A2:A)) will return a array of values as well cell reference from A2 to last non empty cell in column A (Assume you do not have any blank rows inside data). If you have blank row, then you have to use different approach. See this post by #TheMaster
Then LAMBDA() will apply for each unique value return by INDEX() function to gather corresponded values from B column.
Inside lambda, JOIN() will concat those filtered values into one single string.
And finally, by {} results will be combined into on array for output.

Google Sheets formula to lookup value for all rows in another sheet by column names and returning value by column name

I have a Sheet1 with data like this:
one
two
three
four
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
I have Sheet2 with data like this:
alpha
value 1
c
k
g
c
For each row in Sheet2, I want to look up Sheet2.A2:A in Sheet1 according to a lookup column name in Sheet1 and returning values from the associated row in Sheet1 by return column name in Sheet1.
So, a few examples:
Lookup Sheet2.A2:A in Sheet1.three and return Sheet1.one
Lookup Sheet2.A2:A in Sheet1.two and return Sheet1.four
The idea is the formula would specify the lookup column name and return column name and I'd just change it for each lookup I need to do.
Imagine the formula was something like:
=ARRAYFORMULA(
SOMEFORMULA(
A2:A, # lookup this value
GETCOLUMN(Sheet1, "three"), # in this column in Sheet1
GETCOLUMN(Sheet1, "one") # and return the value from this column in Sheet1
)
)
So, the expected result is:
alpha
value
c
a
k
i
g
e
c
a
I can use the new Google Sheet formulas they just released -- except named ranges. I feel like there is some clever trick using them, but I can't come up with it.
Give a try on below formula:
=BYROW(A2:INDEX(A2:A,COUNTA(A2:A)),LAMBDA(x,INDEX(Sheet1!A:D,MATCH(x,INDEX(Sheet1!A:D,,MATCH("three",Sheet1!A1:D1,0)),0),MATCH("one",Sheet1!A1:D1,0))))
By XLOOKUP() function.
=BYROW(A2:INDEX(A2:A,COUNTA(A2:A)),LAMBDA(x,XLOOKUP(x,FILTER(Sheet1!A2:D,Sheet1!A1:D1="three"),FILTER(Sheet1!A2:D,Sheet1!A1:D1="one"),"")))
Sample Sheet Link.
Use HLOOKUP to the get the correct column in Sheet1 and XLOOKUP to get the corresponding column A value:
=ARRAYFORMULA(
XLOOKUP(
A2:INDEX(A2:A,COUNTA(A2:A)),
HLOOKUP("three",Sheet1!A1:Z,SEQUENCE(ROWS(Sheet1!A1:Z)),0),
Sheet1!A1:A
)
)

How to Compare Each Row in One Column for a Match in Another Column

I have values in column B and C. All except 4 from column B should have a matching pair in one of the rows from column C.
I tried to use the code =FILTER(B:B, ISNA(MATCH(B:B, C:C, 0))) but that only shows me 7 matching values. Any idea why it's not matching the 75 of 79 values?
Use this formula
=BYROW(B1:B, LAMBDA(x, IF(x="",,IFNA(INDEX( C1:C, MATCH(x, C1:C, 0), 1),"Missing"))))
Find missing
=IFERROR(FILTER(B:B, ISERROR(MATCH(B:B,C:C , FALSE))), "No match")

How do I add to my QUERY function to add an additional requirement?

=ARRAYFORMULA({
AVERAGE(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(Data!D$2:E856<>"", "♠"&Data!D$2:E856&"♦"&Data!F$2:G856, )),,999^99)),,999^99), "♠")), "♦"),
"select Col2
where lower(Col1) contains '"&LOWER(A2)&"'
offset "&COUNTIF(Data!D$2:E856, A2)-6))})
I have the above formula that I am using. What this does is the following:
The last 6 times A2 shows up in either Column D or E, it accumulates the corresponding value in column F or G. Those 6 values are then turned into an average, as well.
I am trying to add one condition to this. I want it to only take those last 6 instances where column H and I are also something specific.
So when A2 shows up in column D, I only want to use the row if Column I is the value "X". When A2 shows up in column E, I only want to use the row if Column H is "X".
I am unable to get this implemented into my function myself and desperate for some help. One problem is that the "X" search is in reversed column order (ie. when A2 is in D, trying to search I...and when A2 is in E, trying to search G...which isn't the order those appear in the alphabet). Also just not sure where in formula this conditional even needs to go.
Data! just references the sheet I have my dataset dumped into, obviously.

Parsing values from a column while excluding certain values from other column

I have two columns of values of which the second includes a subset of the first. I'm parsing partial matches from the first column with:
=query(A:A, "select A where A ends with 'x'")
It works fine. How would you modify it in order to exclude the shared values?
Here's an example:
A is where we're parsing from, B is the subset we want to discard, C would be the desired result:
filter values to exclude common values with column B
return only values ending in 'x'
Edit
To solve this, you first may need to exclude values from column B, then query result to match only pattern '%x'. Try this formula:
=QUERY(FILTER(A:A,REGEXMATCH(A:A,JOIN("|",FILTER(B:B,B:B<>"")))=false),
"select Col1 where Col1 like '%x'")
Edit #2
Special symbols for regular expressions are \ + * ? [ ^ ] $ ( ) { } = ! < > | : -
If such symbols are met in your data, you need to escape them by \ in order to use regular expressions. So formula REGEXMATCH in this case won't work properly if column B contains special symbols. Possible solution is to replace them like this: [symbol] → [\symbol]. For example, to replece ():
=REGEXREPLACE(text ;"(\(|\)|\*)";"\\$1")
Try using this formula in column C to get the result:
=QUERY(FILTER(A:A,REGEXMATCH(A:A,
REGEXREPLACE( JOIN("|",FILTER(B:B,B:B<>""));"(\(|\)|\*)";"\\$1"))=false),
"select Col1 where Col1 like '%x'")
Original answer
may be using not keyword will work:
=query(A:A, "select A where not A ends with 'x'")
the same as:
=query(A:A, "select A where not A like '%x'")

Resources