7 Replies Latest reply on Nov 10, 2016 6:52 AM by mz5005

    Variables and different calculations to be made

    mz5005

      I have 2 variables A and B. based on the values of these two,different calculations have to be made.

      of course if A and B have many possible values i will define a table.

      but in a case when there are only 2x2 or 2x3 possibilitie, that seems clumsy to me. so do many if/else's.

      what i need is a DO CASE / CASE1 CASE2 kind of command.

      how is that best done in fmp? can't see anything like it in the reference guide.

      any input highly appreciated!

        • 1. Re: Variables and different calculations to be made
          wimdecorte

          Not enough information; can you explain in a bit more detail?

           

          Where should the calculation be made?  In a variable in a script?  In data records?

           

          FM has a case() function to use in calculations.  In scripts you can use IF / ELSE IF / ELSE IF / ELSE / END IF

          1 of 1 people found this helpful
          • 2. Re: Variables and different calculations to be made
            beverly

            testing for?

            • empty/not empty?

            • greater than, less than or equal?

            • ??

            post some example values and what you expect to see, so we can help you with the correct functions to use.

            beverly

             

            p.s. remember

            Left(Functions;3) = "Fun"

             

            • 3. Re: Variables and different calculations to be made
              philmodjunk

              Even with just 2x2 or 3x3 values, it can be better in many cases to use a table rather than "hard code" the values into a calculation if there is even a small chance that you will need to use different values in the future. It's easier to update your system by editing data in a table--doesn't even require a developer, than to redefine a calculation to use different values.

              • 4. Re: Variables and different calculations to be made
                mz5005

                thanks for the input wim,beverly, philmod.

                 

                ok some explanation. i trade forex (currencies). i have a research table with currency pair prices

                (e.g. USD against Euro) for every minute of the day for the last 26 years (of about 20 currency pairs).

                to speed up- and simplify many research queries, i want to calculate values and store them in the same table.

                 

                the below is a fabricated example, to stay away as much as possible from forex explanations.

                so in a given past minute, price can go up/down/remain stable (variable A).

                there are 3 different time periods in a forex day: tokyo, london and new york period (variable B).

                now i wamt to fill per (minute)record a field with a code that shows both the movement and the time perod

                like L- (London period, price down), N- etc

                 

                of course you will say that's not the way to do it, but again it's a fabricated example.

                with if/else 's this takes many steps.

                with (not in fmp) DO CASE it goes much faster:

                DO CASE period ="London"

                       CASE price is "+" $periodmove is "L+"

                       CASE etc

                ENDCASE

                 

                No other way possible in fmp than either (nested) IF/ELSE statements or a table?

                • 5. Re: Variables and different calculations to be made
                  erolst

                  mz5005 wrote:

                  with if/else 's this takes many steps.

                  with (not in fmp) DO CASE it goes much faster:

                  DO CASE period ="London"

                  CASE price is "+" $periodmove is "L+"

                  CASE etc

                  ENDCASE

                   

                  No other way possible in fmp than either (nested) IF/ELSE statements or a table?

                  It has been mentioned that FileMake also has a Case() function, like

                   

                  Case (

                    period = "London" ; londonResult ;

                    period = "Tokyo" ; tokyoResult ;

                    etc.

                  )

                   

                  You could simplify that to something along the lines of

                   

                  Left ( period ; 1 ) & Case ( movement = "up" ; "+" ; "movement" = "down" ; "-" ; "+-" )

                   

                  where the second part is an educated guess, since we don't know how you denote the movement.

                   

                  Since this combines only two criteria, a better possibility would e to use a script that takes values for two input parameters (period, movement) via buttons, then searches the existing fields. Saves one field and storage space.

                  1 of 1 people found this helpful
                  • 6. Re: Variables and different calculations to be made
                    user19752

                    So I add another guess on second part, if there is a difference as number

                    Choose ( Sign ( aValue - anotherValue ) + 1 ; "-" ; "±" ; "+" )

                     

                    // Sign() returns -1,0,+1 then add 1 for Choose() function

                    • 7. Re: Variables and different calculations to be made
                      mz5005

                      thanks eroist and 19752.. i will look at it this weekend.

                      need to study more on functions and see what the implications

                      arebin relationship to script commands (if any).until now only

                      used several get(), max() and avg() functions.