Question is pretty self explanatory. I have two columns (num1, num2) and I just want to return the values that do not match (and not the others):
So the ideal return is simply 2,3,4,5
Edited for clarity**
use:
=FILTER(FLATTEN(A2:B), COUNTIFS(FLATTEN(A2:B), FLATTEN(A2:B))=1)
or if you want it sorted:
=SORT(FILTER(FLATTEN(A2:B), COUNTIFS(FLATTEN(A2:B), FLATTEN(A2:B))=1))
or if you want it joint:
=TEXTJOIN(", ", 1, SORT(FILTER(FLATTEN(A2:B), COUNTIFS(FLATTEN(A2:B), FLATTEN(A2:B))=1)))
You could also use the optional [exactly once] argument of UNIQUE to achieve the same thing in this particular context:
=unique(flatten(A2:B),,1)
This can then be sorted/joined if required.
Related
Google sheets issue. I want a formula that will return TRUE or FALSE if two conditions are met. However for one of the conditions there are two possibilities.
IF A2="Pizza OR Banana" AND B2="Food" then return TRUE
How can I go about it? For now I did the following but I am missing one option (banana):
=IF(AND($A2="Pizza"),$B2="Food")
Thank you!
You could use a formula like
=IF(AND(OR(A2="Pizza", A2="Banana"), B2="Food"), TRUE, FALSE)
Edit:
As pointed out by MattKing, you don't need the IF here at all since AND will give you TRUE/FALSE, you can just use:
=AND(OR(A2="Pizza", A2="Banana"), B2="Food")
try:
=((A2="Pizza")+(A2="Banana"))*(B2="Food")
What if I wanted it to not be case sensitive and to work with Food-FOOD-food and other variants?
=AND(REGEXMATCH($A$2,"(?i)^pizza$|^banana$"),REGEXMATCH($B$2,"(?i)food"))
Use REGEXMATCH instead gives you more control on the conditions.
In this example,
the first REGEXMATCH will do non-case-sensitive check on A2 to see if it is a word started with 'p' end with 'a' spell as 'pizza' or started with 'b' end with 'a' spell as 'banana' (if anything is added before or after 'pizza' and 'banana', such as 'ppizzaa', it returns false),
the second REGEXMATCH do non-case-sensitive check on B2 to see if it is any variants which includes 'food' (even something like 'xFooDy' will return true).
So some agency want to know how many users are allowed to get into their system they send me all users that are allowed, now i want match every user with their data, if the user exit in their column then write "TRUE" if not "FALSE"? Thank you.
Names
Agency1
Allowed?
user565
user44
FALSE
user4851
user4
TRUE
user548
user3
FALSE
user4
user884
FALSE
You should be able to accomplish this using MATCH. Something like:
MATCH(C2,B$2:B)
Note that I am using B$2 here. This means that when you copy this formula to each row, it will continue to look at all of the values in xolumb B. So this is only the formula for the first row.
If MATCH does not find the result, it will return #N/A. This can be handled with IFNA:
IFNA(MATCH(C2, B$2:B), FALSE)
This will return FALSE if the MATCH returns #N/A
Now, to get your TRUE/FALSE value, you need to do a comparison of the above:
IF(IFNA(MATCH(C2, B$2:B), FALSE), TRUE, FALSE)
use:
=INDEX(IFNA(MATCH(B2:B5; A2:A5; ))>0)
Another alternative is to use COUNTIF.
=ArrayFormula(countif(A2:A5,B2:B5)>0)
I am trying to do the following:
From an array [true, true, false] I want to find the number of occurrences of the value true.
I use the collect() to gather the true/false values.
I can check the existence with is in but can't count.
Should I unwind?
For every article I want to get the suggestions in the relationship r. Then If it is more than 3 suggestions, I want to set a property in article to be reviewed: true, otherwise false.
MATCH (a:author)-[r:reviewedby]-(ar:article)
WITH ar, collect(r.suggest) as suggestions
WITH ar, size(suggestions) as nb_sug,
RETURN ar, nb_sug
If you are not making use of false suggestions, for example to calculate a ratio of true/false , this should work.
MATCH (a:author)-[r:reviewedby {suggest:true}]-(ar:article)
WITH ar, count(r) as true_suggestions
WHERE true_suggestions >= 3
RETURN ar
Is there any way that I can get the true value of an OR operation? Something like this?
=OR(value1, value2, value3) return value that is true
try:
=OR(value1, value2, value3)=TRUE
example:
=OR(A1=1, A1=2, A1=3)=TRUE
Taking this question's title literally, the value of any true Or function is always True. However that's probably not what OP is seeking but there's a fundamental misunderstanding that an Or function can have values. Specifically, this question makes a nonsensical assumption that an OR function can have value1, value2, value3. An Or function contains evaluations that return true or false -- no third value possible.
To illustrate, what value would be returned from this Or formula?
=Or(Not(Isnumber(A1)),len(A1)<5,left(C1,1)="G")
However, I understand that this is probably specific to some customized situation. The solution is that some other formula, functionality is needed. If you're evaluating a single cell (i.e. if cell A1 has any three values), then Erik Tyler's proposal of just using an if statement is your answer
=ArrayFormula(IF(OR(A1={5,10,15}),A1,))
(a less elegant but simplified formula that returns the same would be: =if(Or(A1=5,A1=10,A1=15),A1,)
For finding some true values in a range, there are all kinds of possibilities. However to get you started, you might consider using a filter function combined with boolean logic of (evaluation1)+(evaluation2).
See below formula will list off cell addresses of all true values in this Filter function.
=FILTER(Address(ROW(A:A),COLUMN(A:A),4),(A:A=3)+(A:A=5)+(A:A="Hello"))
I would like to split a string by a separator and get only the last part. I
don't care about the rest. I know I can do:
local last
for p in string.gmatch('file_name_test', '_%w+$') do last = p end
Which works, but is, IMHO, ugly.
Is there a more elegant way to say:
local last = string.gmatch('file_name_test', '_%w+$')[1]
Which doesn't work because gmatch returns an iterator (and not a table).
Use string.match which is not an iterator:
local last = string.match('file_name_test', '_(%w+)$')
print (last) --> test
Although the other answers do give you a correct answer for your situation, I am going to propose an answer to your question. Which was to get the first item from an iterator.
And the answer is actually quite simple. Since an iterator is just something that continues to return until it returns nil, we just have to call it!
local first = string.gmatch('file_name_test', '_%w+$')()
I am quite confused however, because in your question you also ask about the last thing it will return. I'm sad to say you cannot do this without iterating over them all, because an iterator cannot "jump ahead".
The pattern _%w+$ will only ever return a single match. That's because you anchored it at the end of the string, so it can only either match or fail to match (if there isn't an underscore followed by at least one %w character at the end).
The g* series of pattern matching are for iterating over a sequence of matches. If you want all the matches all at once (returned as multiple return values), use the non-g-prefixed functions. Like string.match:
string.match('file_name_test', '_%w+$')
If there is no match, then you'll get nil back.