Hi Bill
the short answer is Yes - functions can be nested within one another. There is no limit to the number of levels that you can nest them either. When you call one function as a 'parameter' to another function, you must make sure that the type of value returned by the first function matches the parameter type required by the second.
In general, in a context in which you can use a function, the presence of a function is signalled by an equal sign (=) as in MS Excel. So, for example, in a Query, you put an = in front of a call to a function. Do not put an equal sign in front of any nested functions though.
Functions can be used in sentence templates for narrative reports (as in your example). But when you use a function in these contexts, you must wrap the whole expression in a pair of curly brackets (and then have an '=' sign immediately after the first curly bracket). For example:
In this example, the outer bit
signals a function being used in a sentence template. Within that, the outermost function is RecordId(), which calls another function GetRecord(), which takes the data reference %FACT% as its sole parameter.
Remember you only need or use curly brackets round functions (or function expressions perhaps I should say), in sentence templates. You don't use the curly brackets elsewhere.
Here's another example of a nested call to a function without curly brackets (e.g. for use in a query):
Code: Select all
=Diff(Year(%INDI.BIRT.DATE%),Year(%INDI.~SPOU>BIRT.DATE%))
This expression will calculate the difference in age between a person and their spouse. The outermost function is 'Diff' which takes two parameters. There are two nested calls to the 'Year' function (each of which is passed a data reference referring to a date, as parameter).
Incidentally, as well as calling nested functions, you can also combine them using operators. These can be logical operators (such as 'and', 'or', 'not'), or they can be numeric operators (such as '+', '-', etc). Operators are explained in the Help in the Advanced Topics area. Here's an example of a function call that uses the minus sign (the subtraction operator):
Code: Select all
=Calc(Year(%INDI.BIRT.DATE%) - Year(%IND.~SPOU.BIRT.DATE%))
This is very similar to the previous example. The only difference between the two is that 'Diff' always returns a positive value, whereas 'Calc' will also return negative values.
You can only use operators in the context of a function expression. So if you have two functions and you simply want to put an operator between them, you may need a function like 'Calc' to provide a context for the operator to 'sit' in. The function 'IsTrue' provides a similar role for logical operators.
The only thing with using functions and operators is that it's very easy to make a mistake and fail to match up parameter types and return types etc. They're not very forgiving. If you are trying to put together a very complex expression, I recommend building it up in stages and testing each part if you can.
Hope that makes sense.
Simon