Counting the occurences of value in array - neo4j

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

Related

Return TRUE if two conditions are met but one of them has two options

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

How to match one Text with a whole column? Google sheets

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)

Compare two columns and leave only the values that don't match

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.

Return TRUE of OR operation Google Sheets

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

Username using * in the criteria countif

i m searching sum of class of each student using countif formula, but any student have unique username like A*di (in the image) and so the calculation is false. And any other student using username like </John>, and 'Angel. and make calculation false
Formula: =COUNTIF('Data Asli'!$A:$A,$A$2)
Use SUMPRODUCT(--EXACT(..)) to run an exact, case-sensitive comparison that ignores wildcards:
=SUMPRODUCT(--EXACT('Data Asli'!$A:$A,$A2))
How it works:
EXACT(Value1, Value2) will return TRUE or FALSE, depending on whether the 2 values exactly match (same capitals, no wildcards, et cetera)
-- will convert TRUE/FALSE into 1/0
SUMPRODUCT(Array1[,Array2]) will run down the arrays, multiply the numbers together, then add them. It also forces many functions to both treat a Range as an array, and output an array.
So, as an example, the steps run like this:
=SUMPRODUCT(--EXACT(A1:A5, A2))
=SUMPRODUCT(--EXACT({Value1,Value2,Value3,Value4,Value2}, Value2))
a.k.a.
=SUMPRODUCT(--{EXACT(Value1,Value2),EXACT(Value2,Value2),EXACT(Value3,Value2),EXACT(Value4,Value2),EXACT(Value2,Value2)})
=SUMPRODUCT(--{FALSE,TRUE,FALSE,FALSE,TRUE})
=SUMPRODUCT({0,1,0,0,1})
=2

Resources