Developer Guide

HTQL Query Language Reference

March 29, 2026

What Is HTQL

HTQL is a query language that combines the data retrieval of SQL with the computational familiarity of Excel and the financial intelligence of a CFO’s toolkit.

If you have used Excel functions like NPV, IRR, or PMT, you already understand the mental model. HTQL takes that same approach and applies it to live business data — not static spreadsheets.

A single HTQL expression can retrieve orders, compute margins, evaluate risk, and return a validated result. There is no need for middleware, transformation layers, or external computation engines. The query is the computation.

Querying Data with LOOKUP

The LOOKUP function retrieves data from any table. It works like a database query but reads like a business question.

Basic query:

LET orders = LOOKUP(orders, SHOW(order_id, total, margin), SORT(created_at), TAKE(50))

Filtered query:

LET vip_orders = LOOKUP(orders, WHERE(customer_segment = 'VIP'), SHOW(order_id, total, discount_applied), SORT(total), TAKE(100))

Joined query:

LET enriched = LOOKUP(orders, JOIN([customers], ON([orders.customer_id, customers.id])), WHERE(orders.total > 100), SHOW(orders.order_id, customers.name, orders.margin))

LOOKUP supports WHERE for filtering, SORT for ordering, TAKE for pagination, SHOW for column selection, and JOIN for combining tables. The syntax is intentionally readable — a finance team can understand what the query does without engineering support.

1

Margin & Profitability

GROSS_MARGIN(revenue, cogs) — gross margin percentage CONTRIBUTION_MARGIN(revenue, variable_costs) — contribution per unit NET_PROFIT_MARGIN(net_income, revenue) — bottom-line margin EBITDA(operating_income, depreciation, amortization) — earnings before interest, tax, depreciation EBITDA_MARGIN(ebitda, revenue) — EBITDA as percentage of revenue

2

Valuation & Investment

NPV(rate, cashflows) — net present value of future cash flows IRR(cashflows) — internal rate of return XNPV(rate, cashflows, dates) — NPV with irregular dates XIRR(cashflows, dates) — IRR with irregular dates PV(rate, nper, pmt) — present value FV(rate, nper, pmt) — future value WACC(equity, debt, cost_equity, cost_debt, tax_rate) — weighted average cost of capital

3

Ratios & Health

CURRENT_RATIO(current_assets, current_liabilities) — liquidity QUICK_RATIO(cash, receivables, current_liabilities) — acid test DEBT_TO_EQUITY(total_debt, equity) — leverage RETURN_ON_ASSETS(net_income, total_assets) — asset efficiency RETURN_ON_EQUITY(net_income, equity) — shareholder return INVENTORY_TURNOVER(cogs, avg_inventory) — stock efficiency WORKING_CAPITAL(current_assets, current_liabilities) — operating liquidity

4

Customer & Growth

CLV(avg_revenue, margin, retention_rate, discount_rate) — customer lifetime value CAC_PAYBACK(cac, monthly_revenue, margin) — months to recover acquisition cost LTV_CAC_RATIO(ltv, cac) — unit economics ratio CAGR(begin_value, end_value, periods) — compound annual growth rate BREAK_EVEN_QTY(fixed_costs, price, variable_cost) — units to break even

5

Risk & Cash Flow

VALUE_AT_RISK(portfolio_value, volatility, confidence, horizon) — maximum expected loss SHARPE_RATIO(return, risk_free_rate, std_dev) — risk-adjusted return FREE_CASH_FLOW(operating_cf, capex) — cash available after investment CASH_BURN_RATE(cash_balance, monthly_burn) — monthly cash consumption RUNWAY_MONTHS(cash_balance, monthly_burn) — months of cash remaining DEBT_SERVICE_COVERAGE(net_operating_income, debt_service) — ability to service debt

Variables, Filtering, and Composition

HTQL uses LET to assign variables and compose multi-step queries. This makes complex business logic readable and maintainable.

Computing margin on filtered orders:

LET recent = LOOKUP(orders, WHERE(created_at > '2026-01-01'), SHOW(order_id, revenue, cogs))
LET margin = GROSS_MARGIN(SUM(recent.revenue), SUM(recent.cogs))
RETURN {"total_orders": COUNT(recent), "gross_margin": margin}

Customer lifetime value from live data:

LET customers = LOOKUP(customers, WHERE(segment = 'VIP'), SHOW(customer_id, avg_order_value, purchase_frequency, retention_rate))
LET ltv = CLV(AVERAGE(customers.avg_order_value), 0.35, AVERAGE(customers.retention_rate), 0.10)
RETURN {"vip_ltv": ltv, "vip_count": COUNT(customers)}

Break-even analysis:

LET fixed = 45000
LET price = 89.99
LET variable = 38.50
LET units = BREAK_EVEN_QTY(fixed, price, variable)
RETURN {"break_even_units": units, "contribution_margin": CONTRIBUTION_MARGIN(price, variable)}

Write Operations

HTQL supports full CRUD operations with familiar syntax.

Insert:

INSERT {"product_id": "SKU-001", "price": 89.99, "cost": 38.50} INTO products

Update with filter:

UPDATE {"status": "archived"} IN promotions WHERE(end_date < '2026-03-01')

Upsert (insert or update):

UPSERT {"customer_id": "C-1234"} INSERT {"name": "Jane", "segment": "VIP"} UPDATE {"segment": "VIP"} IN customers

Bulk operations with FOR:

FOR order IN orders WHERE(status = 'pending') BEGIN
  UPDATE {"status": "reviewed"} IN orders WHERE(order_id = order.order_id)
END

All write operations execute within a single transaction. If any step fails, everything rolls back. No partial state.

Statistics and Excel-Style Functions

HTQL includes a full library of statistical functions that work exactly like their Excel equivalents.

Descriptive statistics: AVERAGE, MEDIAN, STDEV, VAR, MIN, MAX, COUNT, COUNTA, COUNTBLANK, COUNTIF, COUNTIFS, SUM, SUMIF

Distribution functions: NORMDIST, NORMINV, TDIST, TINV, FDIST, FINV, BETADIST, BETAINV, BINOMDIST, POISSON, EXPONDIST

Regression and correlation: CORREL, FORECAST, SLOPE, INTERCEPT, RSQ, LINEST

Ranking and percentiles: RANK, PERCENTILE, PERCENTRANK, QUARTILE, LARGE, SMALL

Example — statistical analysis on live data:

LET sales = LOOKUP(orders, WHERE(created_at > '2026-01-01'), SHOW(total))
RETURN {
  "mean": AVERAGE(sales.total),
  "std_dev": STDEV(sales.total),
  "median": MEDIAN(sales.total),
  "p95": PERCENTILE(sales.total, 0.95)
}

One Language. Every Question.

HTQL is designed so that every business question — from a simple order lookup to a complex break-even analysis — can be answered in a single expression.

No transformation layers. No external computation engines. No spreadsheet workarounds.

The syntax is intentionally readable. A finance team can write queries. An engineering team can trust the results. And the system guarantees that every computation is deterministic, repeatable, and auditable.

If you can write an Excel formula, you can write HTQL.

You Don’t Need Better Reporting. You Need Guaranteed Correctness.

Most systems show you what went wrong after the fact. HTQL guarantees correctness before execution. Every transaction validated. Every rule enforced. Every outcome deterministic. This is not analytics — this is control infrastructure.

Profit Guard Insights

Topic

The Leak You Don't See Is the One That Hurts Most

You don’t notice it at first. Sales are coming in. Customers are buying. Your dashboards look fine. Revenue is moving. Everything appears to be working. And yet, something feels off. Margins are tighter than expected. Cash doesn’t stretch as far as it should. Promotions feel like they’re “working”… but not delivering the financial outcome you assumed. This is where most merchants get it wrong. They think profit is lost in big decisions. **It isn’t.** It’s lost in small, repeated, invisible ones.

April 19, 2026

Topic

Discounts Don't Destroy Profit. Lack of Control Does

Discounts are powerful. They move inventory. They increase conversion. They create urgency. They reward customers. Used correctly, they accelerate growth. Used incorrectly, they destroy margin. **The difference is not the discount itself. It’s control.**

April 19, 2026

Topic

Inventory Is Not Stock. It's Capital at Risk

Most merchants think in units. How many items are in stock. How fast they are moving. How many are sold. But this is the wrong lens. Inventory is not stock. It is capital. **Locked capital. Allocated capital. At-risk capital.** Every unit sitting on a shelf represents money that is not working. Every unit in the wrong store represents missed opportunity. Every unit reserved unnecessarily represents blocked revenue.

April 19, 2026

Topic

Loyalty and Gift Cards: The Costs You Don't See Coming

They feel like assets. Loyalty programs build retention. Gift cards generate upfront cash. Customers engage more. Sales increase. On the surface, everything looks positive. But beneath that surface lies a financial reality most merchants ignore. **Loyalty is a liability. Gift cards are deferred obligations.** Every point issued is a future cost. Every gift card sold is revenue not yet earned.

April 19, 2026

Topic

The Moment Everything Changes

There is a moment every serious merchant experiences. It’s not loud. It’s not dramatic. But it is decisive. It’s the moment you realise: **the problem was never sales. It was control.** You were generating revenue. You were running promotions. You were moving inventory. But profit wasn’t following. Not consistently. Not predictably. And you couldn’t explain why.

April 19, 2026