Solved Convert this excel formula to work in query (1 Viewer)

Number11

Member
Local time
Today, 11:16
Joined
Jan 29, 2020
Messages
607
Hello

I have this in a spreadsheet that works all fine i want to create this within a Ms Query...


=IF((OR(AC2="yes",AD2="yes",AE2="yes")),"Yes","")

My fields are

BOOKED
DELIVERED
OUTSTANDING

I tried this but doesnt work

=IF((OR([BOOKED]="yes",[DELIVERED]="yes",[OUTSTANDING]="yes")),"Yes","")
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:16
Joined
Sep 21, 2011
Messages
14,287
I do not believe Access has an OR() function, just the OR keyword ?
 

strive4peace

AWF VIP
Local time
Today, 05:16
Joined
Apr 3, 2020
Messages
1,004
hi @Number11 ,

are the fields defined to be Yes/No in Access? If so

=IIF([field1]=true or [field2]=true or [field3]=true, true, false)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:16
Joined
May 7, 2009
Messages
19,242
or simply:

=IIF([BOOKED] + [DELIVERED] + [OUTSTANDING], "Yes", "")
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:16
Joined
Feb 19, 2002
Messages
43,266
I don't use functions when there are other alternatives.

If you don't know how to create queries, time to fire up the QBE and start.
1. select the table
2. select the columns you want
3. if the fields are YN data type, put true in the criteria line of the first field. Skip down one row and put True in the second. Then down to the third row and True in the third.

The QBE AND's all criteria on the same line and OR's criteria on different lines. If you switch to SQL view, you will see the WHERE clause is

WHERE [BOOKED] = True or [DELIVERED] = True or [OUTSTANDING] = True

buried in a sea of open/close parentheses. Access Looooooooooves parentheses.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:16
Joined
May 7, 2009
Messages
19,242
I don't use functions when there are other alternatives.
if you will follow the OP, he is outputting a "Yes" to a column (possibly calculated).
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:16
Joined
Feb 19, 2002
Messages
43,266
You could be right but the OP never answered the question regarding data type. The concept is the same whether you compare to True or "yes".
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:16
Joined
Feb 19, 2013
Messages
16,610
assuming this is a control and the fields are a boolean type then

=[BOOKED] OR [DELIVERED] OR [OUTSTANDING]

and set the format of the control to ;"Yes";""
 

Number11

Member
Local time
Today, 11:16
Joined
Jan 29, 2020
Messages
607
assuming this is a control and the fields are a boolean type then

=[BOOKED] OR [DELIVERED] OR [OUTSTANDING]

and set the format of the control to ;"Yes";""
No this does not work

Test

BOOKED
DELIVERED
OUTSTANDING
Results
NoNoYes
-1​
NoYesNo
-1​
same result even when a yes is present :)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:16
Joined
May 7, 2009
Messages
19,242
see post#1 for your condition, that is Exactly the same as you write it in excel.
 

Minty

AWF VIP
Local time
Today, 11:16
Joined
Jul 26, 2013
Messages
10,371
PMFJI, but that's what you wanted? Any yes in those three fields = yes?

-1 Is Yes in Access.
 

Number11

Member
Local time
Today, 11:16
Joined
Jan 29, 2020
Messages
607
PMFJI, but that's what you wanted? Any yes in those three fields = yes?

-1 Is Yes in Access.
yes for those with a yes i can also seeing the same when all 3 are the no



BOOKEDDELIVEREDOUTSTANDINGExpr1
NoNoNo
-1​
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:16
Joined
Feb 19, 2013
Messages
16,610
re post #9 - assuming Expr1 is your formula it appears to be working to me - each row has a yes in it and because it is or's it will return true - you just haven't formatted it

;"Yes";""

and what does this mean?

same result even when a yes is present :)

you will get the same result whenever there is a yes
 

Number11

Member
Local time
Today, 11:16
Joined
Jan 29, 2020
Messages
607
re post #9 - assuming Expr1 is your formula it appears to be working to me - each row has a yes in it and because it is or's it will return true - you just haven't formatted it

;"Yes";""

and what does this mean?



you will get the same result whenever there is a yes
no its not working see...

yes for those with a yes i can also seeing the same when all 3 are the no



BOOKEDDELIVEREDOUTSTANDINGExpr1
NoNoNo-1
 

GPGeorge

Grover Park George
Local time
Today, 03:16
Joined
Nov 25, 2004
Messages
1,864
Hello

I have this in a spreadsheet that works all fine i want to create this within a Ms Query...


=IF((OR(AC2="yes",AD2="yes",AE2="yes")),"Yes","")

My fields are

BOOKED
DELIVERED
OUTSTANDING

I tried this but doesnt work

=IF((OR([BOOKED]="yes",[DELIVERED]="yes",[OUTSTANDING]="yes")),"Yes","")
Perhaps this slipped past. Several previous posters did mention it.

In Access, Boolean fields (those with two possible values, i.e. "True" or "False", "Yes" or "No") are stored in tables as -1 and 0, where 0 is false, or no, and -1 is true, or yes.

In your Access expression, therefore, you do NOT check "yes" or "no", you check -1 or 0.

It's possible that you have stored strings, not Booleans, in which case you could put anything in that field in the table, in addition to "yes" or "no" because a string isn't limited to the Booleans.

So, depending on whether you really do have a Boolean, or merely a string of letters, you have to craft the expression appropriately.
 

Number11

Member
Local time
Today, 11:16
Joined
Jan 29, 2020
Messages
607
Perhaps this slipped past. Several previous posters did mention it.

In Access, Boolean fields (those with two possible values, i.e. "True" or "False", "Yes" or "No") are stored in tables as -1 and 0, where 0 is false, or no, and -1 is true, or yes.

In your Access expression, therefore, you do NOT check "yes" or "no", you check -1 or 0.

It's possible that you have stored strings, not Booleans, in which case you could put anything in that field in the table, in addition to "yes" or "no" because a string isn't limited to the Booleans.

So, depending on whether you really do have a Boolean, or merely a string of letters, you have to craft the expression appropriately.
changed to -1 still doent work
 

GPGeorge

Grover Park George
Local time
Today, 03:16
Joined
Nov 25, 2004
Messages
1,864
changed to -1 still doent work
Please state clearly then, what does it mean to say "...doesn't work" ? Do you get an error, wrong answers, NO answers?

Show us the actual result required.

Show us the actual result returned.

Explain the difference to be sure we all understand the nature of the problem.

Thank you.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:16
Joined
Feb 19, 2002
Messages
43,266
We still don't know if you have a text field or a Boolean. But assuming it is text, you were close with your original guess:

=IF((OR([BOOKED]="yes",[DELIVERED]="yes",[OUTSTANDING]="yes")),"Yes","")

should be

=IIF([BOOKED]="yes" OR [DELIVERED]="yes" OR [OUTSTANDING]="yes"),"Yes","")

The IIf() contains three arguments -- IIf(condition, true path, false path)
Any or all of the arguments can be complex. In your case, the condition is compound. You are checking three fields and if any one of them is "yes", then we take the "true path". Otherwise we take the "false path".

The true and false paths can be replaced by entire IIf() statements

IIf(condition, IIf(condition, true path, false path) , false path)
or
IIf(condition, true path, IIf(condition, true path, false path))
or
IIf(condition, IIf(condition, true path, IIf(condition, true path, false path) ) , false path) -- I'm not sure how deeply you can nest but this expression will be very hard for humans to understand so I would recommend creating a UDF which will be easier to code and read.
 

Users who are viewing this thread

Top Bottom