8 Replies Latest reply on Aug 28, 2016 7:31 AM by ucharles

    Calculation involving a Case Function

    ucharles

      Esteemed Filemaker gurus, I used the "Case function" to determine or categorize classes of livestock:

       

      class =

      Case (

      age < 365 and sex = "Female" ; "Calf-Female" ;

      age <  365 and sex = "Male" and Castration = "Yes" ; "Calf-Male" ;

      age <  365 and sex = "Male" and Castration = "No" ; "Calf-Male" ;

       

       

      age < 730 and sex = "Female" ; "Heifer" ;

      age < 730 and sex = "Male" and Castration = "Yes"; "Steer/Tollie" ;

      age < 730 and sex = "Male" and Castration = "No"; "Young Bull" ;

       

       

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

      age ≥ 730 and sex = "Male" and Castration = "Yes" ; "Ox" ;

      age ≥ 730 and sex = "Male" and Castration = "No"  ; "Bull" ;)

       

      The formula worked fine, but now for testing of pregnancy I want to use a combination of  "Heifer" and "Cow" as a group, which would be : age > 365 and sex = "Female". I am currently able to filter LivestockID drop down using a global field that has "Cow", "Bull" and so on. What do I do if I want to limit the drop down to both "Cow" and "Heifer". I have attached the file for easy reference. Go layout LIVESTOCK_PregnancyDiagnosis.

        • 1. Re: Calculation involving a Case Function
          Vaughan

          The logic can be simplified to:

           

          Case(

           

          age < 365 ;  "Calf-" & sex ;

           

          age<730 and sex = "female" ; "Heifer" ;

          age<730 ; case( Castration = "Yes"; "Steer/Tollie" ; "Young Bull" ) ;

           

          sex = "female" ; "Cow" ;

          case( Castration = "Yes"; "Ox" ; "Bull" )

           

          )

          • 2. Re: Calculation involving a Case Function
            ucharles

            Thanks to come to my aid. The calculation works fine for categorizing "Calf-Female",  "Cow", "Bull" etc. But now my problem is that I also want a grouping that is only composed of "Cow" and "Heifer" so that I can use that in the drop-down list.

            • 3. Re: Calculation involving a Case Function
              fmpdude

              I would stay away from the computer and try to use a speadsheet or other tool to make sure you have all your cases considered. When you say "Grouping", perhaps you need to group your data in different ways too.

               

              I find that going to the computer to quickly when I haven't thought things through completely and have all the cases working on paper (or spreadsheet) means I will spend MORE time, not less.

               

              You could also have a database design issue. Not sure, but many problems listed on this forum, where people are asking for "script help" are really database design problems that are trying to be fixed by "clever coding". If your database reflects your situation, things usually will work easily. If your database isn't correct, say, you have the wrong relationships, or even  the wrong basic design, scripts will take forever and never solve the actual problem.

               

              HOPE THIS HELPS.

              • 4. Re: Calculation involving a Case Function
                ucharles

                Fmdude, thanks for your advice, but I think you misunderstood me. If  you have started from the beginning the thread my question could be clearer.

                • 5. Re: Calculation involving a Case Function
                  fmpdude

                  Sorry I wasn't clear. I was really only saying that you need to figure out the cases up front you try to implement them in FM (or any programming environment).

                   

                  In your "original posting", you included a FM file, not a spreadsheet or other documentation listing all combinations you need. When you have lots of Boolean choices, it can get confusing -- especially if you're heads down trying to implement something that's yet to be fully documented.


                  Some folks are "top down", like me, and others like to "jump in" and start coding. My experience on large projects is that the folks that "jump in" end up having lots more problems than the folks who figure out things up front.

                   

                  As an example, would you have a builder build your dream house without blueprints? The "construction metaphor" is totally applicable to serious software development.

                   

                  HOPE THIS HELPS.

                  • 6. Re: Calculation involving a Case Function
                    David Moyer

                    Hi,

                    You might want to add a new calculation field to indicate pregnancy (or eligibility?) ... a Boolean number field equal to (age > 365 and sex = "Female").  0 = not female and/or too young

                    1 of 1 people found this helpful
                    • 7. Re: Calculation involving a Case Function
                      ucharles

                      David! That sounds like the direction worth running to. Why couldn't I think of something like that. When the mind goes blank it just can not rescue itself. THANKS !! I will give it a try.

                      • 8. Re: Calculation involving a Case Function
                        ucharles

                        T H A N K ! ! ! ! What took you so long. I struggle for almost two weeks trying my best to understand a variety a value list, when the solution was in my own formula! I will definitely follow you, just always keep an eye on me if I not somewhere drowning in FM intricacies