If Then Else with OR Eof expected

detriez

Board Regular
Joined
Sep 13, 2011
Messages
193
Office Version
  1. 365
Platform
  1. Windows
I'm using this to create a column.

It fails with Token Eof expected at "tru

Excel Formula:
=If[Country]="Australia" or[Country]="Austria" or[Country]="Belgium" or[Country]= "Brazil" or[Country]="Canada" or[Country] = "Denmark" or[Country]="Finland" or[Country]="France" or[Country]="Germany" or[Country]="Indonesia" or[Country]="Ireland" or[Country]="Israel" or[Country]="Japan" or[Country]="Kuwait" or[Country]="Luxembourg" or[Country]="Malaysia" or[Country]="Mexico" or[Country]="Netherlands" or[Country]="New Zealand" or[Country]="Norway" or[Country]="Philippines" or[Country]="Poland" or[Country]="Russian Federation" or[Country]="Saudi Arabia" or[Country]="Scotland" or[Country]="Singapore" or[Country]="Sweden" or[Country]="Switzerland" or[Country]="Taiwan" or[Country]="United Arab Emirates" or[Country]="United States" then "true" else "false"
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I'm so sorry but I'm trying t understand your message. Besides, is not many details, but I would prefer put all these countries inside a group (i.e. "selected"), and then
Excel Formula:
 IF([country]="selected", "True", "False")

In another way, if you are trying to use an OR nested within an IF, your syntax must be
Excel Formula:
 IF(OR([country]="Australia", [Country]="Austria", ....), "True", "False")

Book1
ABCD
4
5
6countrygroupCountriesColumn1
7ArgentinaFalse
8AustraliaselectedTrue
9AustriaselectedTrue
10BelgiumselectedTrue
11BrazilselectedTrue
12Canada selectedTrue
13ChinaFalse
14CongoFalse
15DenmarkselectedTrue
16FinlandselectedTrue
17FranceselectedTrue
18GermanyselectedTrue
19IndonesiaselectedTrue
20IrelandselectedTrue
21IsraelselectedTrue
22JapanselectedTrue
23KuwaitselectedTrue
24LuxembourgselectedTrue
25MalaysiaselectedTrue
26MexicoselectedTrue
27NetherlandsselectedTrue
28New ZealandselectedTrue
29NorwayselectedTrue
30PeruFalse
31PhilippinesselectedTrue
32PolandselectedTrue
33Russian FederationselectedTrue
34Saudi ArabiaselectedTrue
35ScotlandselectedTrue
36SingaporeselectedTrue
37SpainFalse
38SwedenselectedTrue
39SwitzerlandselectedTrue
40TaiwanselectedTrue
41United Arab EmiratesselectedTrue
42United StatesselectedTrue
43VenezuelaFalse
44
Sheet1
Cell Formulas
RangeFormula
C7:C43C7=IF([@groupCountries]="selected","True","False")
 
Upvote 0
Is this Power BI or Power Query?
 
Upvote 0
This is Power Query

I am trying to create a column and populate it with "True" if the [Country] is in my list and "False" if it is not

The group solution seemed to be elegant but, I'm not sure how to implement it

Here is the syntax I tried. It does not complain about syntax errors but, now I get Expression.Error: The name 'If' wasn't recognized. Make sure it's spelled correctly
I tried different variations of IF(OR( but was getting Token literal Expected on first instance of [Country]

VBA Code:
=IF(OR([Country]="Australia", [Country]="Austria", [Country]="Belgium", [Country]= "Brazil", [Country]="Canada", [Country] = "Denmark", [Country]="Finland", [Country]="France", [Country]="Germany", [Country]="Indonesia", [Country]="Ireland", [Country]="Israel", [Country]="Japan", [Country]="Kuwait", [Country]="Luxembourg", [Country]="Malaysia", [Country]="Mexico", [Country]="Netherlands", [Country]="New Zealand", [Country]="Norway", [Country]="Philippines", [Country]="Poland", [Country]="Russian Federation", [Country]="Saudi Arabia", [Country]="Scotland", [Country]="Singapore", [Country]="Sweden", [Country]="Switzerland", [Country]="Taiwan", [Country]="United Arab Emirates", [Country]="United States"), "True", "False")
 
Upvote 0
You should add a table with the list of countries and then take a look at List.Contains.

Let's say you have a table named Countries which has a column named Name, you could then use this.

Excel Formula:
=List.Contains(Countries[Name], Country)
 
Upvote 0
Solution
Hey @Norie that worked and it allows for easy value additions or deletions.
Thanks all for the help
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,399
Members
449,447
Latest member
M V Arun

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top