Macros

When you want to use a particular (piece of a) formula regularly or at multiple places, you can define a macro. A macro is a named formula. Once defined you can use the macro name  (without spaces) whenever you need the formula. Macro names are shown in green in the formula editor.

Defining macros

To define macros, select Define macros from the settings menu. This bring you to a dialog. 

A the left there is a list of macro names. Use the buttons to add, or delete the selected macro and to change the order.

At the right you can indicate the name of the macro. Make sure this is different from the column or function names. Best start it with a capital letter. The name must start with a letter and can contain letters and digits. It should not contain spaces. Use the underscore (_) symbol for that.

Below the name you can type in the formula for the macro. There is a Test button to test the macro. Finally press Save to save your macro. You can press Reset default to reset the default macros if you changed or deleted them. Your own macros will remain.

Using macros

To use a macro in a filter or other formula, you simply put the macro name in the formula (without spaces). In this way macros can also use other macros (but be careful with recursion where macros call themselves). So if you define macros Long Shot and Short Shot to select the long and short shots, you can use as a filter not LongShot and not ShortShot to get the shots that are neither long nor short. 

Macros versus columns

You might wonder what is the difference between a macro and a user-defined column? Both have a formula that computes a value for each shot. But there are important differences:

User-defined columns can be used as columns in tables and you can create charts of them. More general, you can use them wherever you can select a metric. That is what they are meant for. Macros on the other hand can only be used in filters and other formulas. 

Columns are computed once when the data is loaded. No selections are taken into account. Macros are computed at the moment they are needed. They will work with the current selection. As an example, consider you have a column Good Shot that you give as formula TotalDistance > 0.9*TotalDistance.club_maximum(). The value will be true if the shot is within 10% of the best distance of all the shots with the same club. If you use GoodShot as a filter, only those shots will show up. But when you look at a particular session, none of the shots might show (because this was a rather poor session and no shots where very far). However, if you would have defined a macro GoodShot with the same formula and applied that, the shots with the best distances in the session would be shown. So macros are in some sense local, while columns are global.

Finally, when you define many columns they are all computed and stored when the program loads. This can take a considerable amount of time when you have many shots. Macros are only computed when needed. So the advise is to use macros whenever possible.