Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Formula Error Post Reply Post New Topic
Author Message
robbo1012
Newbie
Newbie


Joined: 29 Oct 2014
Location: United Kingdom
Online Status: Offline
Posts: 6
Quote robbo1012 Replybullet Topic: Formula Error
     Posted: 24 Nov 2014 at 10:09pm
Looking for a little help, quite new to Crystal Reports and got the basics covered but learning more every day.
Got an issue with a report I'm doing for my boss where we have varying monthly sales targets, but I keep getting an error so hopefully someone can fill in the blanks for me.

if{@month} = "January - 2014" then 300000
if{@month} = "February - 2014" then 330000
if{@month} = "March - 2014" then 350000

and so on for rest of year
Tried using and/or etc but cant seem to figure it out.
IP IP Logged
z9962
Senior Member
Senior Member
Avatar

Joined: 04 Jul 2012
Online Status: Offline
Posts: 161
Quote z9962 Replybullet Posted: 25 Nov 2014 at 12:40am
To correct your code you need to add ELSE before each subsequent IF statement
if{@month} = "January - 2014" then 300000
ELSE if{@month} = "February - 2014" then 330000
ELSE if{@month} = "March - 2014" then 350000
 
Another option would be
 
SELECT {@month}
   CASE  "January - 2014"
         :300000
   CASE "February - 2014"
         :330000
CASE "February - 2014"
         :350000
DEFAULT //default is where the above condition has not been met (all other records)
         :0
IP IP Logged
robbo1012
Newbie
Newbie


Joined: 29 Oct 2014
Location: United Kingdom
Online Status: Offline
Posts: 6
Quote robbo1012 Replybullet Posted: 25 Nov 2014 at 1:13am
That works, thanks
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 25 Nov 2014 at 5:22am
You could have kept your original ifs (not the best way to code though).  You would have need to end each if statement with an ;

z9962 is a much cleaner and more efficient way of doing the code.
IP IP Logged
robbo1012
Newbie
Newbie


Joined: 29 Oct 2014
Location: United Kingdom
Online Status: Offline
Posts: 6
Quote robbo1012 Replybullet Posted: 25 Nov 2014 at 11:46pm
much appreciated guys
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum