In Capitally, features like Imports and Taxes allow you to define complex logic using a simple no-code editor. In fact, all the built-in presets are created using this editor - so you can tap into the full capabilities of the application and adapt it to your needs.
This article, will guide you through the common functionality. Please refer to the respective Import and Taxes articles for additional details.
Presets are built using Statements. When they're evaluated, each statement is executed one by one, until either an Exit
statement is encountered, or the list of statements ends.
Whenever a statement needs to evaluate a value, an expression will be used. These can range from a fixed value, like an asset or specific number, through a property value, like a data column or transaction type, to formulas that allow for complex calculations.
You can treat it like a simple scripting language or a complex Excel formula. It provides basic concepts like statements, expressions, variables, functions and loops. But everything is built in a visual way, without coding.
Use the built-in snippets for a great starting point. You can insert them anywhere from the Add statement
menu
The most basic statement is the If
statement. It allows you to make decision based on any properties, and if the conditions match, the nested statements will be executed. If they don't match, the next else
or else if
block will be checked.
To insert a new statement, hover over the space before, after or between existing statements and click the blue divider that shows up and select a statement or preset from the menu.
To insert a new "If" block, hover over the space before, after or between existing if/else and click the grey divider that shows up
Each statement and If block has a menu, which you can use to Copy, Cut, Duplicate and Delete them.
Once you Copy or Cut a statement, you can paste it the same way you add new statements - a Paste option will show up there.
You can copy & paste between two different Tax Presets and even between two different projects.
When complex conditions are needed, you can wrap the first condition within an And/Or block and combine multiple conditions this way.
You can modify an object's property or variable with a Set
statement. You simply choose the property to modify and provide a value.
Fee Currency will be the same as Value Currency
By clicking the to
dropdown you can select different assignment modes, like addition, multiplication, appending or prefixing text and so on.
Value will be increased by the Amount column, while Note appended with Description
Simple scalar values, like text or numbers can be transformed before being assigned. By clicking fx
you can choose one of the transforms. You can stack many transforms together and reorder them by drag & drop.
The Replace
transform let's you replace ocurences of a matching text with something else. For example, you can replace a word (eg. .GR
with .EU
) or remove something by replacing it with nothing.
Replace handles Regular Expressions as well, including the so called capture groups and backreferences. Just toggle the (.*)
button.
Let's say you have a string "apple orange banana" and you want to switch the positions of the first two words. You can use the pattern ([a-z]+) [a-z]+ ([a-z]+)
and replace it with $2 $1
to get "orange apple banana".
Instead of extracting you can just match the part of the string that should be used. It's best used with Regular Expressions, as the first capture group will be extracted.
Expanding on the example with "apple orange banana" from above, having [a-z]+ ([a-z]+) [a-z]+
will extract only the middle word - "orange".
For some properties like Asset or Transaction type you can also map the value from one to another. Click the inverted S
icon next to fx
to add one mapping.
The mapping will check if the incoming value passes a comparison. If yes - the selected value will be used. Mappings will be matched in sequence, and the first one that matches wins.
Properties can have non-matching types. For example, a text will be automatically to number or date, as long as it contains a sensible value (eg. 2024-11-01
or 1st Nov 2024
).
This also works for Accounts, Currencies, Markets or Transaction types, where any text value will be used to search the project or market data.
For assets, you can additionally specify which asset types and markets should be included and in which order of preference.
Like with any scripting language, you can define a variable to hold a value to be reused later on. Each variable has a specific type and initial value. And once it's defined, it can be referenced or Set like any other property.
By default, all variables are local - meaning they're available only within the block they're declared in (including nested blocks) and only after they're declared.
You can switch them to be shared, meaning their value will be initialized only once, and available not only within the whole program, but also between it's invocations - like for every row in an import, or every tax event.
Calculations will only be helpful if you understand the numbers. You can add richly formatted comments anywhere within the preset to better describe the logic.