Risk assessment functions
Know where the business is exposed.
Syntax
Write the function's name and its arguments. The period is written one of three ways: a date window name such as ROLLING_90_DAYS (the date window functions), a start date and an end date such as "2026-01-01", "2026-03-31", or an accounting period id.
COMPUTE_RISK_SUMMARY and COMPUTE_DOMAIN_BREACH_FREQUENCY look at all events and take no period.
COMPUTE_RISK_SUMMARY(accountId, [fields])
COMPUTE_RISK_TREND(accountId, period, [periodEnd], [fields])
COMPUTE_DOMAIN_BREACH_FREQUENCY(accountId)
COMPUTE_AUDIT_LOG(accountId, period, [periodEnd], first, [after], [fields])
COMPUTE_RISK_SCORECARD(accountId, period, [periodEnd])
FINANCIAL_RISK_INTELLIGENCE(accountId, period, [periodEnd], [locationId])Parameters and arguments
Arguments are written in brackets, separated by commas. An argument in square brackets is optional.
COMPUTE_RISK_SUMMARY
Required: YesaccountId
Required: NofieldsCOMPUTE_RISK_TREND
Required: YesaccountId
Required: Yesperiod
Required: NoperiodEnd
Required: NofieldsCOMPUTE_DOMAIN_BREACH_FREQUENCY
Required: YesaccountIdCOMPUTE_AUDIT_LOG
Required: YesaccountId
Required: Yesperiod
Required: NoperiodEnd
Required: Yesfirst
Required: Noafter
Required: NofieldsCOMPUTE_RISK_SCORECARD
Required: YesaccountId
Required: Yesperiod
Required: NoperiodEndFINANCIAL_RISK_INTELLIGENCE
Required: YesaccountId
Required: Yesperiod
Required: NoperiodEnd
Required: NolocationId
Examples
Average risk score, critical events, total money lost to events, and a six axis radar over the last 90 days.
Return type and behaviour
Each function returns one value. The table shows its type, what it does and one way to write it; the examples use the functions in realistic statements.
| Function | Returns | Behaviour | Form |
|---|---|---|---|
COMPUTE_RISK_SUMMARY | record | Average risk score, critical events, total loss, enterprise value erosion and staff overrides across all events | COMPUTE_RISK_SUMMARY("ACCOUNT_ID") |
COMPUTE_RISK_TREND | record | The daily risk score, money impact and event count, with the trend of the score | COMPUTE_RISK_TREND("ACCOUNT_ID", "ROLLING_90_DAYS") |
COMPUTE_DOMAIN_BREACH_FREQUENCY | record | How many medium, high and critical events each area of the business has raised | COMPUTE_DOMAIN_BREACH_FREQUENCY("ACCOUNT_ID") |
COMPUTE_AUDIT_LOG | record | A page of governance events, newest first, with chart ready series | COMPUTE_AUDIT_LOG("ACCOUNT_ID", "ROLLING_90_DAYS", 25) |
COMPUTE_RISK_SCORECARD | record | A risk summary with a six axis radar built from refunds, discounts, stock, suppliers, margin leakage and capital | COMPUTE_RISK_SCORECARD("ACCOUNT_ID", "ROLLING_90_DAYS") |
FINANCIAL_RISK_INTELLIGENCE | record | The five CFO risk sections and a plain sentence that sums them up | FINANCIAL_RISK_INTELLIGENCE("ACCOUNT_ID", "ROLLING_90_DAYS") |
Every answer from COMPUTE_RISK_SUMMARY, COMPUTE_RISK_TREND, COMPUTE_DOMAIN_BREACH_FREQUENCY, COMPUTE_AUDIT_LOG and COMPUTE_RISK_SCORECARD also carries meta (the engine version, when it was computed and the function's name) and narratives, the written commentary stored for your account, newest period first.
COMPUTE_RISK_SUMMARY answers
| Field | Type | Meaning |
|---|---|---|
avgRiskScore | number | The average risk score of all events |
criticalCount | whole number | Events of Critical severity |
totalLoss | money | The money impact summed over all events |
totalEvErosion | money | The yearly rate of loss capitalised at the cost of capital: the value a business loses if the losses keep going |
staffOverrideCount | whole number | Events whose code is a staff override |
metricLabels, metricValues | lists | The same five measures as chart labels and numbers |
COMPUTE_RISK_TREND answers
| Field | Type | Meaning |
|---|---|---|
trend | list of records | date, riskScore, financialImpact and eventCount for each day with events |
seriesDates, seriesRiskScores, seriesFinancialImpact, seriesEventCounts | lists | The same days as parallel lists for a chart |
riskScoreSlope | number | Change in the daily score per day. Present when at least 2 days have events and the score was asked for |
riskScoreTrend | list of numbers | The fitted line for each day |
riskScoreRsq | number | How well a straight line fits the daily scores |
COMPUTE_DOMAIN_BREACH_FREQUENCY answers
| Field | Type | Meaning |
|---|---|---|
domains | list of records | domain and count, the most breaches first |
seriesDomainLabels, seriesBreachCounts | lists | The same as parallel lists for a chart |
COMPUTE_AUDIT_LOG answers
| Field | Type | Meaning |
|---|---|---|
edges | list of records | Each is cursor and node, where node holds the fields asked for: eventId, code, severity, riskScore, financialImpact, aggregateId, createdAt, detail |
pageInfo | record | hasNextPage and endCursor |
totalCount | whole number | Events in the range |
seriesDates, seriesSeverities, seriesRiskScores, seriesFinancialImpact, seriesCodes | lists | The page as parallel lists for a chart |
COMPUTE_RISK_SCORECARD answers
| Field | Type | Meaning |
|---|---|---|
avgRiskScore | number | The average risk score in the period |
criticalEvents | whole number | Critical events in the period |
totalFinancialImpact | money | The money impact of the period's events |
topRiskDomains | list of text | The three areas with the most events |
riskRadar | list of records | axis and value for Refund Risk, Discount, Inventory, Supplier Risk, Margin Leakage and Capital Efficiency |
radarLabels, radarValues, domainLabels, domainCounts | lists | The radar and the domain counts as parallel lists |
FINANCIAL_RISK_INTELLIGENCE answers
| Field | Type | Meaning |
|---|---|---|
cfoSummary | text | One sentence on profit, returns against the cost of capital, margin pressure, takeover exposure and concentration |
financialHealth | record | economicProfit, nopat, roic, wacc, roicWaccSpread, waccCoverageRatio, waccCoverageLevel, breakEvenGap, breakEvenRevenue, investedCapital, ebit, revenue, grossProfit, totalFixedCosts |
riskPressure | record | discountDependencyRate, discountCap, discountDependencyLevel, marginCompressionFlag, marginTrend (period, grossMarginRate), fixedCostBurdenRate, shippingLeakage, saasCost, saasCostRate, operatingLeverage |
capitalValuationRisk | record | earningsStabilityCv, earningsStabilityLevel, revenueConcentrationTop1, revenueConcentrationHhi, enterpriseValueDelta, takeoverVulnerabilityScore, takeoverRiskLevel, tvsFactors (factor, triggered, points) |
operationalRisk | record | gmroi, gmroiLevel, daysInventoryOutstanding, inventoryCapital, locationProfitability (one record for each location with revenue, margins and atRisk), customerRefundRate, customerQualityScore |
forecastStress | record | forecastVsRequiredMargin, requiredMargin, forecastGapLevel, stressScenarios (label, revenueShock, stressedRevenue, stressedEbit, stressedEp), breakEvenRevenue, downsideEp |
Errors and exceptions
| Error | What happened | How to recover |
|---|---|---|
HTQL-5001 | The function was given the wrong number of arguments. The message names the function and the counts | Give it the arguments listed under Parameters |
HTQL-1004 Unsupported function | The name is not a function this engine runs | Check the name and its spelling against this entry |
Limitations
COMPUTE_RISK_SUMMARYandCOMPUTE_DOMAIN_BREACH_FREQUENCYcover every event, with no period.COMPUTE_DOMAIN_BREACH_FREQUENCYcounts only medium, high and critical severity.- The enterprise value erosion in
COMPUTE_RISK_SUMMARYuses a cost of capital of 12 per cent when no macro settings are stored. - A field list that names none of the known fields answers an empty record.
- Severity labels are
Low,Medium,HighandCritical.
Permissions and security
These functions read your governance events, per order profit, refunds, order lines, inventory movements, settings and stored narratives. The caller needs read access to the records named, and nothing is written.
They are governed by the same read access as the tables they read, so no separate grant is needed beyond it.
Best practices
- Name the fields you need in the summary, trend and audit calls: each field is a separate calculation.
- Call
COMPUTE_RISK_TRENDbefore you act on a single bad day: one critical event can move a quarter's average. - Open
FINANCIAL_RISK_INTELLIGENCEwhen the scorecard shows capital or margin pressure.