Boolean Operators Missing From Cell Expressions In Excel?
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

Boolean Operators Missing From Cell Expressions In Excel?

(how's that for a geeky title)

Okay, the simple excel function i wanted to teach someone to write:

How would you write that as a cell function?

I haven't done much excel lately. Here's how I thought it would be written:

=IF(B12 >=1986 AND B12 <= 2000,1,0) <-- Nope!!!

How about:

=IF(B12 >=1986 && B12 <= 2000,1,0) <-- Uh-uh!! No siree!!

(i was still refusing to look up help at this point...)

Forget it... i'll nest the logic...

=IF(B12 >=1986, IF(B12 <= 2000), 1 ,0) ,0) <-- Yes this worked. But...

Yuck. I mean... honestly!!

So I tried...

=IF(B12 BETWEEN (1986, 2000), 1, 0) <-- Doesn't work
=IF(B12 IN (1986...2000), 1, 0) <-- Doesn't work

(also tried with square brackets, curly brackets, angle brackets, pipe symbols, the phoenician alphabet, a donkey's leg, a bat's wing....)

Looked in help... and oh my god how lispy is this:

=IF(AND(B12 >=1986, B12 <= 2000), 1, 0)

How am i supposed to teach my frail elderly aunt to grok that?

It's elegant from the computer's point of view... it's an expression tree... i'd enjoy writing a program to parse that, i know i would... but teaching a regular human to read it, use it, debug it, maintain it, trust it, tweak it, share it, co-opt it, .... never.

This is a symptom of excel decimating the competition a long time ago and then stagnating. Yes: the dodo effect.

If excel were a version 2 product, I'd say "hey that's pretty good", but we're talking about version 11 here. They should've allowed cell functions like this: "= IF (B12 >=1986 AND B12 <= 2000, 1, 0) " long long ago. Operators... operators... not just functions. Lisp had it back in 1902. ah forget it. I wonder how wikiCalc handles cell functions? or spreadsheets.google.com?





'Daniel Bowen' on Thu, 31 Aug 2006 05:11:27 GMT, sez:

=IF(ABS(B12-1993)<=7,1,0) :-)



'lb' on Thu, 31 Aug 2006 05:44:20 GMT, sez:

top answer Dan!



'Kalpesh' on Thu, 31 Aug 2006 09:23:41 GMT, sez:

It seems excel has a different way of "AND"ing the conditions

=IF(AND(A1>=1986, A1<=2000), 1, 0)



'Jody' on Thu, 31 Aug 2006 09:43:20 GMT, sez:

Daniel's solution is elegent; however it isn't obvious from looking at it that it does the logic you asked; what if you wanted to change the years? You would have to do a bit of math in order to update the formula.

Here one solution:
=IF(A1 >= 1986, IF(A1<=2000,1,0), 0)

A user looking at that formula can easily see what values needs to be changed.



'Simon' on Fri, 01 Sep 2006 14:19:31 GMT, sez:

Excel doesn't have any operators. All it has is *functions* that are named like operators. Once you figure that out, it will make sense AND(StopTryingInExcel)



'googlexcel' on Sat, 02 Sep 2006 23:17:20 GMT, sez:

google spreadsheet does it the same way...



'Nick Hodge' on Sun, 03 Sep 2006 23:25:45 GMT, sez:

Is A1 a date?

Oh my gawd I hope not, otherwise your poor elderly aunt is going to end up in a loony bin



'Calybute' on Sun, 09 Sep 2007 07:01:46 GMT, sez:

Try this...

=IF(A1<1986,0,IF(A1<=2000,1,IF(A1>2000,0)

It works and is it simpler than IF(AND)s to understand...



'Calybute' on Sun, 09 Sep 2007 07:03:43 GMT, sez:

Actually, that is essentially Jody's, written in longhand... but I found it easier to read....



'greg' on Wed, 28 Oct 2009 11:56:57 GMT, sez:

Excel will evaluate the function to boolean.
=AND(A1>=1986,A1<=2000)

To coerce the TRUE/FALSE to 1,0 just multiply by 1 or use the double unary --.

=--AND(A1>=1986,A1<=2000)

=1*AND(A1>=1986,A1<=2000)



'Brian Minton' on Thu, 10 Jun 2010 22:52:45 GMT, sez:

Excel does not have boolean operators, but it does have *arithmetic* operators. Excel uses the convention 0 = FALSE, any non-zero number = true, so you can do something like this:

=IF((B12 >=1986) * (B12 <= 2000),"yes","no")

This is not exactly intuitive though, and in your particular example, since you only want a 1 or a 0, the if statement is not even strictly necessary, as you could do the following:

=(B12 >=1986) * (B12 <= 2000)




name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. But the right to delete any post for any reason is reserved. Don't make me do it. Aim for constructiveness. Comments may be republished, emailed to your loved ones or printed and used as toilet paper. Also, I get particularly nasty on comment spam. It's not worth even trying to post comment spam here -- your html is escaped, and your links are given a rel='nofollow'. By attempting to post a comment, you understand that if the comment is considered spam, at my absolute discretion, your IP address may be used as the target of a prolonged distributed denial of service attack. Your electricity might suddenly stop working. Your car tyres will go mysteriously flat. You will suffer permanent hairloss. Your dreams will be filled with terrifying monsters. And in any case I reserve the right to record and publish your IP address.

 

TimeSnapper is a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

 

NimbleText - FREE text manipulation and data extraction

NimbleText is a Powerful FREE Tool

Use it for:

  • extracting data from text
  • manipulating text
  • generating code

It makes you look awesome. Use it right now! Go on! Hurry! Don't walk, run!

 

Articles

Just Wally Just Wally
The Correct Order for a First Time Viewing of The Lord Of The Rings The Correct Order for a First Time Viewing of The Lord Of The Rings
A new era for Android. A new era for Android.
Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion
Got CSV in your javascript? Use agnes. Got CSV in your javascript? Use agnes.

Archives Complete secretGeek Archives

TimeSnapper -- Automated Screenshot Journal TimeSnapper: automatic screenshot journal
NimbleText -- World's Simplest Code Generator NimbleText: Code Generator, Text Manipulator, Data Extractor

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker


[powered by Google] 


How to be depressed How to be depressed
You are not inadequate.



Recommended Reading


the little schemer


The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
Thomas White
OJ Reeves
Eric Sink

Aggregated Links

proggit
dzone
hacker news
dot net kicks

Human Link Machines

interesting finds
a continuous learner's weblog
arjan's world
weekly link post

LinkedIn profile
LogEnvy - event logs made sexy
Computer, Unlocked. A rapid computer customization resource
PhysioTec, Brisbane Specialist Physiotherapy & Pilates
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2006 .: privacy