7 Replies Latest reply on Dec 30, 2016 4:28 PM by erolst

    Combining or nest calculations

    lindseym

      Hello,

       

      I have two calculations that I want to combine and I am having trouble doing so. Both work individually. When I try to combine them, FMP throws and error:

       

      Screen Shot 2016-12-30 at 11.00.10 AM.png

       

      and then highlights this:

       

      Screen Shot 2016-12-30 at 11.00.17 AM.png

       

       

       

      The first: (removes leading zeros from field-- I took this off the forum, so please don't think I know what I am doing! )

       

      https://community.filemaker.com/thread/120925?q=removing%20leading%20zeros curtesy of LaRetta_1

       

      Let ( [

      t = LeftWords ( Location Calculation ; 1 ) ;

      x = Filter ( LeftWords ( t ; 1 ) ; "0123456789" )  = LeftWords ( t ; 1 ) ;

      l = Length ( LeftWords ( t ; 1 ) ) ;

      n = GetAsNumber ( LeftWords ( t ; 1 ) )

      ] ;

      Case (

      x ; n & Right ( t ; Length ( t ) - l )  ; t

      ) // end case

      ) // end let

       

       

      And the second: (substitutes)

       

      Substitute (

      ${Copy)} ;

      ["XLEVEL#" ; "*" & Level from Space] ;

      ["LEVEL#" ; Level from Space] ;

      ["STAIR#" ; Stair from Space] ;

      ["BLDG#" ; Building from Space] ;

      ["LOC#" ; LeftWords ( Location Calculation ; 1 )] ;       This is the substitution that would need the leading zeros removed

      ["TBD" ; TextStyleAdd ( "TBD" ; HighlightYellow )]

       

       

      )

       

       

      Any guidance is appreciated!

       

       

      Happy New Year!

       

       

      -L

        • 1. Re: Combining or nest calculations
          erolst

          Convert the final result calculation of the Let( ) into another variable declaration, and make the second calc the end result:

           

          Let ( [

            t = LeftWords ( Location Calculation ; 1 ) ;

            x = Filter ( LeftWords ( t ; 1 ) ; "0123456789" )  = LeftWords ( t ; 1 ) ;

            l = Length ( LeftWords ( t ; 1 ) ) ;

            n = GetAsNumber ( LeftWords ( t ; 1 ) ) ;

           

            locationCalculationWithoutLeadingZeroes =

              Case (

                x ;

                n & Right ( t ; Length ( t ) - l ) ;

                t

               ) 

            ] ; 

           

            // And the second: (substitutes)

           

            Substitute (

              ${Copy)} ;

                [ "XLEVEL#" ; "*" & Level from Space ] ;

                [ "LEVEL#" ; Level from Space ] ;

                [ "STAIR#" ; Stair from Space ] ;

                [ "BLDG#" ; Building from Space ] ;

                [ "LOC#" ; locationCalculationWithoutLeadingZeroes ] ;

                // This is the substitution that would need the leading zeros removed

                [ "TBD" ; TextStyleAdd ( "TBD" ; HighlightYellow ) ]

            )

           

          )

          1 of 1 people found this helpful
          • 2. Re: Combining or nest calculations
            siplus

            Please refrain from naming your fields with a free combo of reserved words and spaces, it makes everything so unnecessarily difficult.

             

            "Building from space test"... WTF

            • 3. Re: Combining or nest calculations
              David Moyer

              Hi,

              I see a variable called ${copy)} ... that won't work.  I avoid anything but letters and numbers when naming variables.

              Edited for clarification ...

              • 4. Re: Combining or nest calculations
                lindseym

                Thanks. This worked.. and more importantly I understand why it worked.

                 

                 

                • 5. Re: Combining or nest calculations
                  lindseym

                  siplus & @David Moyer

                   

                   

                  In a way I'm chuckling.

                   

                  My typical Variable for ${copy)} is ${copy (Side A)}  (created LONG before I new the mayhem it would cause!)and I always get called out on it.... this time I thought to remove  the parenthesis but messed it up.

                   

                  As far as the "Test"  I am working on FMP so I can't test my calculations as you could in Advanced. I was advised to create a separate field and slowly build my calculations instead of trying to do it all at once-- which has really helped me out. I was also losing calculations that did work when I tried to add additional nested calculations and messed up. Hence the test (which I can easily delete when the time comes). -- as far as the "Building from Space - I am sure it isn't the right way to do things, but for me it shows that the field is going to parse the building name from the Space field. WYSIWYG --- In reality if I started from scratch, I could probably lose 50% of the fields and set much better naming parameters but it's been about 6 months of me learning with only the help of this forum and the internet. I have been toying with the idea of taking a class or two to get the very basics down... and if you have any suggestions of what type of class to look for at a local college I would totally look in to it

                   

                  I totally get it. I am a graphic designer  by trade and get so annoyed when files come across my desk titled:

                   

                  Brochure 2017-Version 2 Revised Final FINAL Print.pdf

                   

                  I am appreciative of all your help -- even reading through old discussions I see your names a bunch -- and know you have helped me out on specific inquiries.

                   

                  Happy New Year

                  • 6. Re: Combining or nest calculations
                    user19752

                    ${} is not variable, it is escaping syntax for identifier (table / field name).

                    But it is interesting as you wrote, it can be a variable in Let() function but can't be defined in "Set Variable" dialog.

                    I agree never using such names.

                    1 of 1 people found this helpful
                    • 7. Re: Combining or nest calculations
                      erolst

                      user19752 wrote:

                       

                      ${} is not variable, it is escaping syntax for identifier (table / field name).

                      That's because FileMaker is so accommodating. Other platforms wouldn't let you get away with that, or make you actively wrap it into protective clothing.