CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2010
    Posts
    8

    Crystal Reports Formula

    I suspect I am making this much more difficult than it is but here is what I am tying to do:

    I have a database that that has an employee information table in it. In that table there is a field called department number. I need to to write a formula that will say if the department number is is between 100 and 199 then display the text "A", if it is between 200 and 299 then display the text "B", if it is between 300 and 399 then display the text "C".

    I am having a heck of a time getting this to work out.

  2. #2
    Join Date
    Apr 2008
    Location
    Pittsburgh
    Posts
    103

    Re: Crystal Reports Formula

    select {department.number}
    case 100 to 199:"A"
    case 200 to 299:"B"
    case 300 to 399:"C"

    Hope that helps

  3. #3
    Join Date
    Mar 2010
    Posts
    8

    Re: Crystal Reports Formula

    I keep getting a message that says "A string is required here" with that formula. However, I think the formula is correct. not sure what the problem is....

  4. #4
    Join Date
    Jul 2005
    Posts
    1,083

    Re: Crystal Reports Formula

    If the field is String type then
    Code:
    select {department.number}
    case "100" to "199":"A"
    case "200" to "299":"B"
    case "300" to "399":"C"

  5. #5
    Join Date
    Mar 2010
    Location
    Indonesia
    Posts
    1

    Re: Crystal Reports Formula

    Hi wensley

    You could try the alternative formula (i'm using basic syntax) :

    if ToNumber(department.number) between 100 and 199 then
    Formula = "A"
    else if ToNumber(department.number) between 200 and 299 then
    Formula = "B"
    else if ToNumber(department.number) between 300 and 399 then
    Formula = "C"
    end if

    it's seems to be longer, but hope it work 4 you

  6. #6
    Join Date
    Jul 2008
    Posts
    12

    Re: Crystal Reports Formula

    Quote Originally Posted by jggtz View Post
    If the field is String type then

    Code:
    select {department.number}
    case "100" to "199":"A"
    case "200" to "299":"B"
    case "300" to "399":"C"
    Quote Originally Posted by Yudi Purwanto View Post
    Code:
    if ToNumber(department.number) between 100 and 199 then
    Formula = "A"
    else if ToNumber(department.number) between 200 and 299 then
    Formula = "B"
    else if ToNumber(department.number) between 300 and 399 then
    Formula = "C"
    end if
    Between the two, the Select Case structure is more elegant, and should include the Default case:

    Code:
    Select {department.number}
      Case "100" to "199":
        "A"
      Case "200" to "299":
        "B"
      Case "300" to "399":
        "C"
      Default:
        ""

  7. #7
    Join Date
    Mar 2010
    Posts
    8

    Re: Crystal Reports Formula

    Thanks, guys! that worked perfectly! I do have one more question though

    I would love to insert a parameter field into this report that lets the user choose either "A" "B"or "C". for instance:

    It would be great if the user could input "A" and only pull up those records that are associated with "A". The Select, Case worked perfectly to separate the records, but is it possible to add a parameter that will let the user only choose to view "A" on the report?

  8. #8
    Join Date
    Apr 2008
    Location
    Pittsburgh
    Posts
    103

    Re: Crystal Reports Formula

    That is easy enough. Create your parameter and then in the select expert

    Code:
    {?parameter} = {department.number}

  9. #9
    Join Date
    Mar 2010
    Posts
    8

    Re: Crystal Reports Formula

    that sounds easy enough. The department.number is a range of numbers which is why I needed that select, case statement to separate them out.

    So I created my parameter, but how do I make that work in the select expert if the department numbers are just a long list of numbers? So for instance, thanks to the select statement I have labeled them as "A" B" or "C" (the formula is @plant_ID and the parameter I just created is called {?plant}, what I need is for the user to choose Either A, B, or C and the report only display the results of the select statement. I hope this is not too confusing.....

  10. #10
    Join Date
    Mar 2010
    Posts
    8

    Re: Crystal Reports Formula

    Hey never mind! I just worked it out! Thanks so much to everyone who replied!

  11. #11
    Join Date
    Jul 2005
    Posts
    1,083

    Re: Crystal Reports Formula

    Post your solution, to close the thread

  12. #12
    Join Date
    Mar 2010
    Posts
    8

    Re: Crystal Reports Formula

    Basically what I did was not just add the parameter formula in the select expert but changed the current parameter. Without bogging you down in the details (it is a rather complex report) I already had a necessary date range parameter set up so I just appended a new line to it to filter but department as well as date. Pretty easy stuff...I just wasn't thinking when I initially looked at it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured