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
All calculations use
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.1
Open your VDM
Go to DataBridge → Virtual Data Marts and open the VDM you want to configure.
2
Add a Calculation transform
In the Transformations panel, click + and select Calculation.
3
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
4
Save the VDM
Click Save. The calculation is now available as a measure in any experiment using this VDM.
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
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
1
Add Calculation
Click + in the Transformations panel → select Calculation.
2
Configure
- Field Name:
Wtd Avg ESG Score - Calculation Type: Weighted Average
- Value Field:
ESG_SCORE - Weight Field:
MKT_VAL - Partition By:
ACCT_CD
3
Verify preview
The SQL Preview should show:
4
Save
Click Save.
Step 3: Add % of Fund
1
Add Calculation
Click + → Calculation.
2
Configure
- Field Name:
% of Fund - Calculation Type: Percentage of Total
- Value Field:
MKT_VAL - Partition By:
ACCT_CD
3
Save
Click Save.
Step 4: Add Median Analytic Value
1
Add Calculation
Click + → Calculation.
2
Configure
- Field Name:
Median Analytic - Calculation Type: Percentile
- Value Field:
ANALYTIC_VAL - Percentile:
0.5 - Partition By:
ACCT_CD
3
Save
Click Save.
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.