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

Combining or nest calculations

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:

and then highlights this:

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

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

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

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

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

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

• 5. Re: Combining or nest calculations

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

\${} 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

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.