1 2 Previous Next 28 Replies Latest reply on May 30, 2016 10:12 AM by ucharles

    Case function

    ucharles

      This is not working: how to I write it correctly?

       

      Case

      age ≥ 720 and sex = "Male" and Castration =  1 ; "Ox" ;

       

       

      What do I do if I want evaluate 3 condition to be true to obtain a result?

        • 1. Re: Case function
          Mike_Mitchell

          Case requires parentheses. Also, if you leave the last semicolon in place, you'll need to put a default result. Like this:

           

          Case ( age ≥ 720 and sex = "Male" and Castration =  1 ; "Ox" ; "Other" )

          1 of 1 people found this helpful
          • 2. Re: Case function
            RickWhitelaw

            Since there is only one test this could be an If function.

            • 3. Re: Case function
              erolst

              RickWhitelaw wrote:

              Since there is only one test this could be an If function.

              Just use Case() always, and be done with it. 

              • 4. Re: Case function
                dtcgnet

                ucharles wrote:

                 

                This is not working: how to I write it correctly?

                 

                Case

                age ≥ 720 and sex = "Male" and Castration = 1 ; "Ox" ;

                 

                 

                What do I do if I want evaluate 3 condition to be true to obtain a result?

                Case (

                age >= 12 and sex = "Male" and Castration=0 ; "Bull" ;

                age >= 720 and sex = "Male" and Castration=1 ; "Ox" ;

                age <=720 and sex = "Male" and Castration=1 ; "Steer" ;

                "")

                 

                You will probably want to have a label for every animal, so cover each designation as needed. Males can be bulls, oxen, or steers, as far as I know. Females are cows, but I don't know if there are separate designations amongst those. A case statement will return the first TRUE condition, so order them that way.

                 

                Interesting question!

                1 of 1 people found this helpful
                • 5. Re: Case function
                  ucharles

                  Thanks!!! .

                  • 6. Re: Case function
                    ucharles

                    Case ( age ≤ 345 and sex = "Female" ; "Calf-Female" ;

                        age ≤ 345 and sex = "Male" ; "Calf-Male";

                     

                      age ≤ 720 and sex = "Female"; "Heifer" ;

                      age ≤ 720 and sex = "Male" and Castration = 1; "Steer/Tollie" ;

                     

                      age ≥ 720 and sex = "Female" ; "Cow" ;

                     

                        age ≥ 720 and sex = "Male" and Castration = 1; "Ox" ;

                        age ≥ 720 and sex = "Male" and Castration = 0; "Bull" ; )

                     

                    This is only returning "Cow" only. What could I have done wrong?

                    • 7. Re: Case function
                      erolst

                      dtcgnet wrote:

                       

                      A case statement will return the first TRUE condition, so order them that way.

                       

                      If they're mutually exclusive, that doesn't matter; but it's preferable to order them by likelihood or frequency, so on average, fewer calculations have to performed. And on that same note, you can do some grouping, e.g.

                       

                      Case (

                      sex = "male" ; // otherwise, don't bother with the rest

                      Case (

                          not isCastrated ;

                         "Bull" ; // not dependent on age

                          Case ( age > 720 ; "Ox" ; "Steer" ) ; // 720?? 12?

                        )

                      )

                       

                      which may no be correct in this subject matter, but the principle should be clear.

                       

                      From a certain number of variations, a lookup table is the better method, so you can encode these predicates in the relationship definition.

                      • 8. Re: Case function
                        dtcgnet

                        First thing, in two instances, change <= 720 to simply <720.

                         

                        Sent from my iPhone

                        • 9. Re: Case function
                          erolst

                          As outlined above, I would re-arrange this as:

                           

                          Case (

                            age <= 345 ;

                              Case ( sex = "Female" ; "Calf-Female" ; "Calf-Male" ) ;

                            age <= 720 ;

                              Case ( sex = "Female" ; "Heifer" ; Castration ; "Steer/Tollie" ) ; // no non-castrated in that age range?

                              Case ( sex = "Female" ; "Cow" ; Castration ; "Ox" ; "Bull" )

                          )

                           

                          And maybe check your input data!? There is still the GIGO principle …

                          • 10. Re: Case function
                            ucharles

                            It is the castration part that is giving me the problem. It is working for the calves and the cow, but when it comes to Bull and Steer and Ox then the problem starts.

                            • 11. Re: Case function
                              dtcgnet

                              The castration part is always a problem.

                               

                              Go to the actual calculation window and take a screen shot. We'll need to see the actual calculation, not a cut and paste.

                               

                              Just as an aside, I played baseball for a VFW (Veterans of Foreign Wars) baseball team in high school. Our team was rural, and across the street from the field was a "bull-milking" operation. I played left field, closest to the barn. We had a home field advantage because the opposing teams didn't usually understand why there was so much noise coming from the barns at certain times of the day.

                               

                              You'll have a good answer pretty soon.

                              • 12. Re: Case function
                                ucharles

                                The problem is with "Castration", I omitted everything and only used Castration =1 and Castration = 0 and it is not returning anything. Castration is based on a value list called "castrated" which uses a radial button for yes and no. Could that be the problem.

                                • 13. Re: Case function
                                  dtcgnet

                                  Yep. That would be the problem. If your value list uses "Yes" and "No", then comparing to 1 and 0 won't work.

                                  • 14. Re: Case function
                                    beverly

                                    They both have merit.

                                    IF ( I__2use = CASE; useCASE ; useIF )

                                     

                                    beverly

                                    1 2 Previous Next