Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Nested if in Formula Post Reply Post New Topic
Author Message
chimp8471
Newbie
Newbie


Joined: 12 Jan 2012
Location: United Kingdom
Online Status: Offline
Posts: 4
Quote chimp8471 Replybullet Topic: Nested if in Formula
     Posted: 12 Jan 2012 at 4:50am
Hi,
 
This is my first delv into crystal reports so please excuse my simple question.
 
I have a field called "Signature" which tracks who has signed of an activity.
 
I am trying to group a few people together to display which shift they are on.
 
Example:
 
tom - shift 1
dick - shift 1
harry - shift 2
paul - shift 2
 
what i want to achieve is create a field that calcultates:
 
if [signature] = tom then "Shift 1"
if [signature] = dick then "Shift 1"
if [signature] = harry then "Shift 2"  
etc....
 
Can someone please help
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 12 Jan 2012 at 4:59am

In the formual editor

right click on formula field
select new
name it (e.g. Shift_Identiifier)
 
if {table.signature} in ['tom','dick'] then 'Shift 1' else
if {table.signature} in ['harry','paul'] then 'Shift 2' else 'Not Identified'
 
Place in the detail section to result
The Final else(not identified) is optional but helps to debug and group outliers.
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 12 Jan 2012 at 5:04am
if {table.signature} = "Tom" then "Shift 1" else
if {table.signature} = "Dick" then "Shift 1" else
if {table.signature} = "Harry" then "Shift 2" else
... etc
 
You were close ^^
 
I however prefer case statements, they're easier to read and modify. :)
 
select {table.signature}
case "Tom","Dick": "Shift 1"
case "Harry": "Shift 2"
default: "Unknown";


Edited by rkrowland - 12 Jan 2012 at 5:07am
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 12 Jan 2012 at 5:06am
We're treading on each other's toes DBlank... =)
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