NL2SQL: configure metrics and filters¶
Metrics connect business names to executable numerical definitions. Open Semantic configuration → NL2SQL semantics → Metrics in the knowledge base and create a metric.
Prepare the data¶
The knowledge base needs available structured tables. If creation is disabled and requests a data source, import and inspect tables first. Prepare the metric name, calculation source, units, period, and filters.
Base metrics¶
A base metric aggregates one source table, such as calculating revenue from order amounts.
Enter the identifier and business name, plus optional description and synonyms.
Select a base metric and its source table.
Choose the aggregation function and field; check the multiplier and unit.
Add fixed filters if required by the definition.
Inspect previews and validation, save, and test a range you can calculate manually.
Field |
Meaning or example |
|---|---|
Identifier |
|
Name |
A business-readable name such as “Net revenue” |
Description |
Units, refund treatment, and applicable scope |
Synonyms |
Alternative names with exactly the same definition |
Source table |
The table containing the intended business data |
Aggregation function and field |
How to summarize which field, using available form options |
Multiplier |
Numerical conversion consistent with the unit |
Fixed filters |
Conditions such as excluding canceled orders or limiting business scope |
Derived metrics¶
A derived metric performs arithmetic on existing metrics, such as a ratio or difference. Create the required base metrics first.
Select the source table.
Insert base metrics from the reference list and combine them with operators, numbers, and parentheses.
Review the formula preview and errors.
Save and compare the result with its base-metric values.
If the same table supplies revenue and cost, (revenue - cost) / revenue can describe gross margin. Define how zero revenue should be handled.
Current formulas support only base metrics from the same source table. Changing the table clears the formula. A formula cannot reference itself or a nonexistent identifier, supports at most 200 characters, and must contain at least two metrics or numbers joined by an operator.
Filters and condition groups¶
For each condition, choose a field, comparison, and value. Set-membership conditions accept multiple values; range conditions need both endpoints; null and not-null checks need no comparison value.
Connect conditions with AND or OR. Group complex conditions so the inner group is evaluated before its outer combination. For example: paid AND (direct channel OR partner channel). Check parentheses in the SQL hierarchy preview so an OR does not unintentionally widen the result.
Complete or remove unfinished conditions and empty groups before submitting.
Validate a metric¶
Ask a standard question and synonymous variants over a small known dataset. Check values, units, filters, and zero-value cases. Formula validation establishes acceptable syntax, not a correct business definition.