How can I use three conditions in a single cell? (IF+AND) - if-statement

Say I have a B60 and C60 cells which are both checkbox.
I only need three results,
If B60 is true
If B60 isn't true.
If B60 and C60 are true.
I tried using
=IF(B60=TRUE,"B60 is true",AND(C60=TRUE,"Both B60 and C60 are true")
how can i fix this

use:
=IF((B60=TRUE)*(C60=TRUE), "Both B60 and C60 are true",
IF(B60=TRUE, "B60 is true", "B60 isn't true"))

Another option with CHOOSE:
=ArrayFormula(IF(LEN(A1:A),CHOOSE(B1:B+C1:C*B1:B+1,"B is false", "B is true", "B&C are true"),""))

use:
=IF(AND (C60=FALSE, B60=TRUE),"B60 is true", IF(AND (C60=TRUE, B60=TRUE), "Both B60 and C60 are true", ""))
Explain:
If B60 is true
If B60 isn't true.
If B60 and C60 are true.
is equal:
only B60 is true (C60 is false) "B60 is true"
both B60 and C60 are true => "Both B60 and C60 are true"
so we create 2 conditions:
AND (C60=FALSE, B60=TRUE)
AND (C60=TRUE, B60=TRUE)

Related

Print one result after combining multiple expression results using jq

I want to have the output of either true or false.
I have this syntax
.[] | (if (select(.displayName=="display")) then "yes" else "no" end)
This is the json source
[{"displayName":"display","message":"bla bla"}, {"displayName":"test","message":"bla bla"}]
I only need to query against the array and if the value im looking for exists in one of them I need the output to be "yes", and if it doesnt a "no". So a single output value is what I am looking for.
This evaluates to "yes", however, if the value display is not present in the json, it does not output "no", its just empty. Can anyone tell me why?
Here is a snippet to try: https://jqplay.org/s/WKcZh91hk8L
The idea is right, but you shouldn't be using select for this. The way select works is by evaluating the boolean expression provided inside (..) and returning the object, if the expression evaluates to true and skip the object from being considered/printed on false.
On your code, for the object that evaluates to false, select is evaluated as select(false) which as explained above returns nothing - this is not evaluated to boolean false condition. i.e. the return value of select is not a boolean value.
To use explicit boolean conditions, drop the select from expression and to summarise the result to a single value do something like below
if ( [ .[] | .displayName == "display" ] | any ) then "yes" else "no" end
Demo on jqplay
The way this works, is any can evaluate an array of boolean values and produces true as output if any of the elements of the array are true. We collect the match condition results to the array and apply any on it. i.e. [true, false] evaluates to true, thereby printing yes only once
A concise solution is possible with select:
select( any(.displayName=="display") ) | "yes" // "no"

GREL: how to use OR in an if statement

How can I use 'OR' in GREL if statement?
I want to construct something like this
if(contains(value, "this") OR contains(value, "that"), True, False)
This worked for me
if(or(contains(value, "this"), contains(value, "that")), True, False)

How to apply a and not b pattern match using regex in R

I would like to filter a list by only keeping items that contain dimension or that contain metric and not penetration
I can filter to those that contain dimension OR metric and penetation, but I can't see how to switch the logic of the second case to metric and not penetration
Example below:
> library(stringr)
> var_list <- c("other", "dimension_1", "dimension_2", "metric_1", "metric_2", "metric_3_penetration")
> str_detect(var_list, "dimension|(?=.*metric)(?=.*penetration)")
[1] FALSE TRUE TRUE FALSE FALSE TRUE
Result that I would like to return from the str_detect is below:
[1] FALSE TRUE TRUE TRUE TRUE FALSE
You can use a combination of a negative and positive lookaheads for the second case:
> library(stringr)
> var_list <- c("other", "dimension_1", "dimension_2", "metric_1", "metric_2", "metric_3_penetration")
> str_detect(var_list, "dimension|^(?=.*metric)(?!.*penetration)")
[1] FALSE TRUE TRUE TRUE TRUE FALSE
The ^(?=.*metric)(?!.*penetration) regex matches when a string has metric and does not have penetration.
To only check for whole words, add (?:\b|_) boundaries:
str_detect(var_list, "dimension|^(?=.*(?:\\b|_)metric(?:\\b|_))(?!.*(?:\\b|_)penetration(?:\\b|_))")
A logical combination of grepl calls is simple and involves no packages:
grepl("dimension",var_list) | (grepl("metric",var_list) & !grepl("penetration",var_list))
## [1] FALSE TRUE TRUE TRUE TRUE FALSE

trying to validate string as boolean Coldfusion

I'm currently trying to validate if a string is exactly true or false as I'm building a spreadsheet importer using CF10.
My users will either enter in one of the following.
NULL, which will equate to false
TRUE which obviously equates to true
FALSE which again will equate to false.
I'm trying to use the isValid('boolean',variable.data) to validate if the data is in fact a boolean string or not. However after reading quite a few posts I can see that it will validate true if its a positive number and false if it is a negative one etc.
I'm wondering if anyone has an easy fix to getting boolean validation working for strings easily ? Is this more a regular expressions scenario to make it work properly ?
Any help greatly appreciated.
Assuming you mean the literal string "NULL", one option is using list functions. Search a list of allowed values, ie "true,false,null". If the entry is found, it is valid:
<cfif listFindNoCase("true,false,null", theValue)>
this is a valid boolean value
<cfelse>
not found. do something here...
</cfif>
Then a simple string comparison would return false for everything other than the literal string "true":
isTrue = compareNoCase(e, "true") eq 0 ? true : false`
If you need to evaluate whether a string is exactly "true" or "false", then you are not doing a boolean comparison, you are doing a string comparison.
So to that end, you'd be wanting to use compare() or compareNoCase() (depending on how rigid you need to be).
You could just do some logic or am I missing something.
<cfset booleanResult = enteredValue eq 'TRUE' ? true : false />

What are all the values that ColdFusion considers "falsy" and "truthy"?

I'm looking to compile a complete list of values that ColdFusion considers falsy and truthy. The ones I know of are:
//falsy values
false
"false"
0
"no"
//truthy values
true
"true"
!= 0
"yes"
Is there anything that I'm missing here?
There's a neat little article on that here http://www.coldfusionmuse.com/index.cfm/2010/2/5/Booleans.and.Coldfusion
but of course officially it's http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec09af4-7fd0.html
In Boolean expressions, True, nonzero numbers, and the strings “Yes”, “1”, “True” are equivalent; and False, 0, and the strings “No”, “0”, and “False” are equivalent.
Boolean evaluation is not case sensitive. For example, True, TRUE, and true are equivalent.
So, using your terminology:
//falsy values
False
"False"
0
"No"
//truthy values
True
"true"
!= 0
"Yes"
"1"