Documentation Index
Fetch the complete documentation index at: https://docs.tarvah.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Tarvah’s calculation engine generates SQL window functions and aggregate expressions for common financial analytics patterns. Calculations are defined as a VDM transformation — the same level as expressions, aggregates, groupings, and time series — and automatically flow through to experiments and dashboards.Supported Calculation Types
| Type | SQL Pattern | Use Case |
|---|---|---|
| Percentage of Total | value / NULLIF(SUM(value) OVER (PARTITION BY ...), 0) | Position weight in account, sector allocation |
| Weighted Average | SUM(value * weight) OVER (...) / NULLIF(SUM(weight) OVER (...), 0) | Weighted yield, weighted ESG scores |
| Percentile | PERCENTILE_CONT(n) WITHIN GROUP (ORDER BY value) OVER (...) | Median analytics, distribution analysis |
| Custom | User-defined SQL with ${field} template references | Any custom formula |
NULLIF(..., 0) for safe division and COALESCE for null-safe arithmetic.
Define a Calculation on a VDM
Calculations are a VDM transformation type. Add them from the VDM editor alongside expressions, aggregates, groupings, and time series.Configure the calculation
Fill in the form:
- Field Name — the name that will appear as a selectable measure in experiments
- Calculation Type — Percentage of Total, Weighted Average, Percentile, or Custom SQL
- Value Field — pick a numeric column from the VDM’s selected columns
- Weight Field — (weighted average only) pick the weighting column
- Partition By — select columns to group by (produces
PARTITION BYin SQL) - Percentile — (percentile only) value between 0 and 1
- Custom SQL — (custom only) raw SQL with
${columnName}references
Calculation Types in Detail
Percentage of Total
Calculates what fraction of a total a value represents, partitioned by one or more columns. Form fields: Value Field, Partition By Generated SQL:0.20 (20%).
Weighted Average
Calculates a weighted average using a value field and a weight field. Form fields: Value Field, Weight Field, Partition By Generated SQL:Percentile
Calculates a percentile value within a partition. Form fields: Value Field, Percentile (0-1), Partition By Generated SQL:Custom SQL
Write arbitrary SQL with${columnName} placeholders that resolve to the actual column references from your VDM.
Form field: Custom SQL
Example input:
Calculation Object Structure
When working with calculations programmatically (e.g., in thecalculationConfiguration array), use this structure:
Fields
| Field | Type | Required | Description |
|---|---|---|---|
customFieldName | string | Yes | Display name — appears as a selectable measure in experiments |
calculationType | string | Yes | One of: percentage_of_total, weighted_average, percentile, custom |
valueField | string | Conditional | Column to calculate on. Required for all types except custom. |
weightField | string | Conditional | Weighting column. Required for weighted_average. |
percentile | number | Conditional | Value between 0 and 1. Required for percentile. |
partitionBy | string[] | No | Columns to partition by. Produces PARTITION BY in SQL. |
customSql | string | Conditional | Raw SQL expression. Required for custom. Supports ${columnName} references. |
Example: Alpha Core Portfolio Calculations
This walkthrough uses the Alpha Core model (FCT_POSITION_SECURITY_LEVEL with DIM_ACCOUNT and DIM_SECURITY joins) to set up three common financial calculations.
Step 1: Open the VDM
Open the VDM that was created from the Alpha Core LookML import. Go to DataBridge → Virtual Data Marts → select the VDM.Step 2: Add Weighted Average ESG Score
Configure
- Field Name:
Wtd Avg ESG Score - Calculation Type: Weighted Average
- Value Field:
ESG_SCORE - Weight Field:
MKT_VAL - Partition By:
ACCT_CD
Step 3: Add % of Fund
Configure
- Field Name:
% of Fund - Calculation Type: Percentage of Total
- Value Field:
MKT_VAL - Partition By:
ACCT_CD
Step 4: Add Median Analytic Value
Configure
- Field Name:
Median Analytic - Calculation Type: Percentile
- Value Field:
ANALYTIC_VAL - Percentile:
0.5 - Partition By:
ACCT_CD
Step 5: Save the VDM
Click Save on the VDM. All three calculations are now available as measures in experiments and SDK imports.Step 6: Use in an experiment
Create an experiment from the VDM. DragWtd Avg ESG Score onto the Y axis and Account Code onto the X axis. The chart shows the market-value-weighted ESG score per account — not a simple average.
Using Calculations in Experiments
Once a calculation is saved on the VDM, it appears as a selectable measure when building experiments:- Create an experiment from the VDM
- In the chart configuration, drag the calculation field (e.g., ”% of Fund”) onto the Y axis
- Set aggregation to as-is — the calculation’s SQL is used directly
Calculations produce
operationType: "EXPRESSION" in the query engine, which means the full SQL window function is placed directly in the SELECT clause. This works across all 5 supported databases: Snowflake, Postgres, Oracle, IBM DB2, and SQL Server.BI Import
LookML models define raw building blocks — dimensions (ACCT_CD, MKT_VAL, ESG_SCORE) and standard measures (SUM, AVG, COUNT). Complex calculations like weighted averages and percentiles are not defined in LookML — they are configured on the VDM after import.