Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: IF THEN ELSE display problem Post Reply Post New Topic
Author Message
iousb
Newbie
Newbie


Joined: 04 Mar 2009
Location: United States
Online Status: Offline
Posts: 3
Quote iousb Replybullet Topic: IF THEN ELSE display problem
     Posted: 04 Mar 2009 at 6:33pm

I created a Formula Field called emp_payroll_desc (#2), and the code to create each of the 16 lines for the report (grouping on LOC code) at the bottom of this page appears below. I also created 4 counters (#1) which were incremented based on the value of a table field called ‘AREA’. Depending on whether Field ‘AREA’ equaled B,C,D or E would depend on which counter would be incremented based on columns B,C,D or E. Column A is a total of columsn B,C,D,E for each row.  So I first grouped on LOC code and also grouped on emp_payroll_desc in order to get totals for each line.

 

The problem I am having is that when  I preview the report, only some of the rows are displayed for each LOC code. When I tested each IF condition (by commenting out all thief ELSE conditions), each individual line was displayed on the report with correct counts. Yet not all of the lines are displayed when I factor in all the IF and ELSES at the same time as displayed on report. It almost seems like some of the lines are being overwritten. I cannot figure out how to set up the code to display all 16 lines for each LOC code. By the way, I have tried just doing IF xxx THEN YYY; for each  condition but all that does is displays the last condition ‘14.  U.S. CITIZENS              65,490       669     1,971     2,269    60,581’ insteadof all 16 lines.

 

Can anyone help?

 

#1 (counters for columns B,C,D and E)

 

 Formula field for Column B (us_terr)            -  code: if {AREA} = "2" then 1

 Formula field for Column C (forgn_ctry)      - code: if {AREA} = "3" then 1

 Formula Field for Column D (dc_area)         - code: if {AREA} = "4" then 1

 Formula Field for Column E (out_dc_area)  - code: if {AREA} = "5" then 1

    

#2 (emp_payroll_desc code)

 

IF ({WRK_SCHED} in ["I","J"] AND

    {ACT_IND} = "4") THEN  '16. INTERMITTENTS NOT WRKING'

ELSE IF ({WRK_SCHED} in ["I","J"] and

         {ACT_IND} <> "4") then '8. INTERMITTENT'

ELSE IF {POS_TEN} IN ["P","M"] THEN '2. TOTAL IN PERM POSITIONS'

ELSE IF {WRK_SCHED} IN ["F","G","H"] THEN '3. FULL TIME'

ELSE IF ({WRK_SCHED} IN ["F","G","H"] AND

         {POS_TEN} IN ["P","M"]) THEN '4. FULL TIME IN PERM POS'

ELSE IF ({WRK_SCHED} IN ["F","G","H"] AND

         {APT_CAT} = "1") THEN '5. FULL TIME W/PERM APTS'

ELSE IF {WRK_SCHED} IN ["P","Q","R","S","T"] THEN '6. PART TIME'

ELSE IF ({WRK_SCHED} IN ["P","Q","R","S","T"] AND

         {APT_CAT} = "1") THEN '7. PART TIME W/PERM APTS'   

ELSE IF {POSN_OCCUPD_ID} = "1" THEN '9. COMPETITIVE SERVICE'

ELSE IF ({POSN_OCCUPD_ID} = "1" AND

         {APT_CAT} = "1") THEN '10. WITH PERMANENT APPTS'

ELSE IF {POSN_OCCUPD_ID} in ["2","3","4"] THEN '11. EXCEPTED SERVICE & SES'

ELSE IF ({POSN_OCCUPD_ID} in ["2","3","4"] AND

         {APT_CAT} = "1") THEN '12. WITH PERMANENT APPTS'

ELSE IF LEFT({CURR_PAY_PLAN},1) IN ["W","X"] THEN '13. WAGE SYSTEMS'

ELSE IF {CITIZENSHIP} IN ["8","5"] THEN '15. NONCITIZENS'

ELSE IF NOT({CITIZENSHIP} IN ["8","5"]) THEN '14. U.S. CITIZENS';

 

 

 

LOC CODE   - ABC

_____________________________  ________  ________  ________  ________  ________

  EMPLOYMENT PAYROLL                   TOTAL         U.S.       FOREIGN        D.C.      OUTSIDE

TURNOVER & CEILING DATA             ALL AREA     TERR.     CNTRIES       AREA    D.C. AREA

                                                                 - A-              -B-              -C-              -D-            -E-

 

  1. GRAND TOTAL EMPLOYMENT      66,162         669            2,609          2,269       60,615

  2.   TOTAL IN PERM POSITIONS       64,890         667            2,247          2,072       59,904

  3.   FULL TIME                                    65,246         669            2,598          2,238       59,741

  4.     FULL TIME IN PERM POS          64,074         667            2,237          2,047       59,123

  5.     FULL TIME W/PERM APTS        55,436         601            1,571          1,933       51,331

  6.   PART TIME                                       905             0                  11               31           863

  7.     PART TIME W/PERM APTS            438             0                   0               12           426

  8.   INTERMITTENT                                  11             0                   0                 0             11

  9.   COMPETITIVE SERVICE             34,390         105             1,651         1,713      30,921

 10.    WITH PERMANENT APPTS       32,566         103             1,353         1,671      29,439

 11.  EXCEPTED SERVICE & SES       31,772         564                958            556      29,694

 12.    WITH PERMANENT APPTS       23,308         498                218            274      22,318

 13.  WAGE SYSTEMS                         21,040         251                471            294      20,024

 14.  U.S. CITIZENS                              65,490         669             1,971         2,269      60,581

 15.  NONCITIZENS                                   672             0                638                0             34

 16.  INTERMITTENTS NOT WRKING    1,147             0                   2               13        1,132


 

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 04 Mar 2009 at 7:15pm
not sure this will solve all your problems but in some cases you need to flip your sequence of the if then else if. The below highlighted items need to have the AND statements first otherwise you will never get those records because the first condition was met and it will drop it into that set instead of the next one. With an If then else if... process a record will only show up in the first condition it meets and then stop. It will not show up in multiple ways even if more than one condition could have been met. Also I put a final item to see if anything was slipping through which can be useful in figuring out what records you are not catching.
 
IF ({WRK_SCHED} in ["I","J"] AND

    {ACT_IND} = "4") THEN  '16. INTERMITTENTS NOT WRKING'

ELSE IF ({WRK_SCHED} in ["I","J"] and

         {ACT_IND} <> "4") then '8. INTERMITTENT'

ELSE IF {POS_TEN} IN ["P","M"] THEN '2. TOTAL IN PERM POSITIONS'

ELSE IF ({WRK_SCHED} IN ["F","G","H"] AND

         {POS_TEN} IN ["P","M"]) THEN '4. FULL TIME IN PERM POS'

ELSE IF {WRK_SCHED} IN ["F","G","H"] THEN '3. FULL TIME'

ELSE IF ({WRK_SCHED} IN ["F","G","H"] AND

         {APT_CAT} = "1") THEN '5. FULL TIME W/PERM APTS'

ELSE IF ({WRK_SCHED} IN ["P","Q","R","S","T"] AND

         {APT_CAT} = "1") THEN '7. PART TIME W/PERM APTS'   

ELSE IF {WRK_SCHED} IN ["P","Q","R","S","T"] THEN '6. PART TIME'

ELSE IF ({POSN_OCCUPD_ID} = "1" AND

         {APT_CAT} = "1") THEN '10. WITH PERMANENT APPTS'

ELSE IF {POSN_OCCUPD_ID} = "1" THEN '9. COMPETITIVE SERVICE'

ELSE IF ({POSN_OCCUPD_ID} in ["2","3","4"] AND

         {APT_CAT} = "1") THEN '12. WITH PERMANENT APPTS'

ELSE IF {POSN_OCCUPD_ID} in ["2","3","4"] THEN '11. EXCEPTED SERVICE & SES'

ELSE IF LEFT({CURR_PAY_PLAN},1) IN ["W","X"] THEN '13. WAGE SYSTEMS'

ELSE IF {CITIZENSHIP} IN ["8","5"] THEN '15. NONCITIZENS'

ELSE IF NOT({CITIZENSHIP} IN ["8","5"]) THEN '14. U.S. CITIZENS';

ELSE 'MISSED RECORD'
IP IP Logged
iousb
Newbie
Newbie


Joined: 04 Mar 2009
Location: United States
Online Status: Offline
Posts: 3
Quote iousb Replybullet Posted: 05 Mar 2009 at 8:47am

Thanks for the response....

I tried this and even though more lines are being displayed, still not all the lines are. My counts are not even close to what they need to be though. Most of them are much less than they need to be.

Since each condition needs to be checked, is there any other way to do this without using IF THEN...ELSE because every record should satisfy most of the conditions and if not, I still want to display the description and counts of 0 for each column if need be.

Thanks
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 05 Mar 2009 at 9:03am

Question...Do you want every record to show up in only one condition or do you want them to have the possibiity of showing up in more than one condition?



Edited by DBlank - 05 Mar 2009 at 9:04am
IP IP Logged
iousb
Newbie
Newbie


Joined: 04 Mar 2009
Location: United States
Online Status: Offline
Posts: 3
Quote iousb Replybullet Posted: 05 Mar 2009 at 9:39pm
I want every record to have the possibiity of showing up in more than one condition.
Thanks
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Mar 2009 at 7:26am
Just to clarify this is one way to address this if you need any one record to be able to show up in more than Job title (not in the columns ABCD...) and it is labor intensive Angry
If the above is not true and each job can only show up in one of the 16 job types it will be worth rethinking your If then Else formula and fixing it...
 
Also, using this process you cannot group and you will have to use a lot of running totals to get your numbers...
Create a distinct formula per condition.
 
e.g. Formula 1 as "16"
IF ({WRK_SCHED} in ["I","J"] AND

    {ACT_IND} = "4") THEN  1 else 0

Formula 2 as " '8"
IF ({WRK_SCHED} in ["I","J"] and

         {ACT_IND} <> "4") then 1 else 0

Repeat for each possibility (job #).
This will allow you to check every record for every condition and give you a summable formula field to work with per job type.
Next create a running total using each formula as a a sum for each column condition (A,B,C,D,E) (a total of 16 formulas times 5 columns...)
Place the running totals in the RF with text items to identify each.
 
Not easy but it should work.
If you choose this method do one or to fields and test it out to make sure you are getting what you need before getting to far along and finding out this process is flawed Unhappy
If anyone else has a simpler solution feel free to chime in
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