NexusQL Language Reference
This document provides an overview of the NexusQL language — a custom SQL-like syntax for querying Nexus, the OLAP-like database provided by Biron.
It focuses on the distinctive features that differ from standard SQL. For standard SQL constructs (e.g., CASE expressions, ORDER BY, etc.), please consult standard SQL references.
1. Overview
Section intitulée « 1. Overview »NexusQL is designed for analyzing metrics along various dimensions over specific periods. It introduces specialized functions (metric,
dimension, refDateDimension) and imposes certain constraints on FROM, and date filtering. Subqueries and window functions are
supported with some limitations detailed below.
2. Key Differences from Standard SQL
Section intitulée « 2. Key Differences from Standard SQL »- Mandatory
FROMClause
- You must always query from
datamodel(i.e.,FROM datamodel) when retrieving metrics and dimensions. - If you need to perform window functions on the result of a subquery, or combine multiple subqueries, you can use an outer query that
references an inner query. However, the inner query typically uses
FROM datamodel.
- Metrics / Aggregate functions
- Standard aggregate functions like
SUM,COUNT, orAVGare replaced by a single function calledmetric(). - The first argument of
metricis always a string composed of<viewCode>.<metricCode>. - Example:
metric('transactions_order_date.billing_with_vat')retrieves the metric namedbilling_with_vatfrom the viewtransactions_order_date. - Additional arguments can specify overrides or filters (e.g.,
overrideRefDate,addWhere), discussed later. - At least one metric must be selected.
- Dimensions / Slicers
- To segment or group by a dimension, use the function
dimension('dimensionCode'), use thedimension('dimension_code')function. - For example,
dimension('customer_age')references a dimension calledcustomer_age. - For time-based grouping, use
refDateDimension(INTERVAL 1 <period>). - The
<period>can beDAY,WEEK,MONTH,QUARTER, orYEAR. - Example:
refDateDimension(INTERVAL 1 MONTH)groups data by month. - If you want to group results by a dimension, you must include that dimension in the
GROUP BYclause (either directly or by using the same alias assigned inSELECT).
- Filtering
- You must filter on
refDatein theWHEREclause using a BETWEEN operation for lower and upper boundaries. - Example:
WHERE refDate BETWEEN '2023-01-01' AND '2023-01-31'. - Additional boolean conditions can filter dimensions, e.g.,
dimension('customer_age') > 30.
- Grouping
- All selected expressions (except
metricones) must appear in theGROUP BYclause. - In practice, dimensions or any expression aliased in the
SELECTmust be grouped on.
3. Basic Query Skeleton
Section intitulée « 3. Basic Query Skeleton »A straightforward NexusQL query has the following form:
SELECT [refDateDimension(INTERVAL 1 MONTH) AS date_alias,] [dimension('some_dim') AS dim_alias, ...] metric('view.metric_code') AS metric_alias[, ...] FROM datamodel WHERE refDate BETWEEN 'YYYY-MM-DD' AND 'YYYY-MM-DD' [AND other dimension filters ...] [GROUP BY [ date_alias, dim_alias, ...]] [ ORDER BY [ date_alias, dim_alias, metric_alias, ... ]] [ LIMIT <n,m>]Note: All non-metric columns or expressions in
SELECTmust appear inGROUP BY. TheWHEREclause must include arefDatefilter.
4. Functions and Special Constructs
Section intitulée « 4. Functions and Special Constructs »4.1 metric('<view>.<metric>'[, additionalArgs, ...])
Section intitulée « 4.1 metric('<view>.<metric>'[, additionalArgs, ...]) »- Description: Retrieves a predefined metric.
- Mandatory Argument: A string indicating
<viewCode>.<metricCode>. - Optional Arguments:
overrideRefDate('start', 'end'): Temporarily change the date range for this metric (could be used only once per metric).addWhere(<expression>): Apply additional filters only for this metric, the expression is similar to the one that you could use inWHEREclause.
Example:
SELECT metric('transactions_order_date.billing_ht') AS total_billing_ht FROM datamodel WHERE refDate BETWEEN '2025-01-01' AND '2025-01-31'More examples for overrideRefDate and addWhere bellow.
3.2 dimension('dimension_code')
Section intitulée « 3.2 dimension('dimension_code') »- Description: References a dimension by its code.
- Usage: In
SELECT,WHERE, orGROUP BYto specify dimension-based grouping or filtering.
Example:
SELECT dimension('order_shipping_address_country') AS country, metric('xxx.yyy') FROM datamodel WHERE refDate BETWEEN '2023-01-01' AND '2023-02-28' AND dimension('customer_age') > 30 GROUP BY country3.3 refDateDimension(INTERVAL 1 <period>)
Section intitulée « 3.3 refDateDimension(INTERVAL 1 <period>) »- Description: Generates time segments based on a specified interval, e.g., day, week, month.
- Allowed Periods:
DAY,WEEK,MONTH,QUARTER,YEAR.
Example:
SELECT refDateDimension(INTERVAL 1 WEEK) AS weekly_date, metric('xxx.yyy') FROM datamodel WHERE refDate BETWEEN '2023-01-01' AND '2023-06-30' GROUP BY weekly_date ORDER BY weekly_date3.4 overrideRefDate('start', 'end')
Section intitulée « 3.4 overrideRefDate('start', 'end') »- Description: When passed as an additional argument to
metric, it replaces the default date range for that metric.
Example:
SELECT metric('transactions_order_date.billing_ht') AS current_billing, metric('transactions_order_date.billing_ht', overrideRefDate('2024-01-01', '2024-01-31')) AS last_year_billing FROM datamodel WHERE refDate BETWEEN '2025-01-01' AND '2025-01-31'3.5 addWhere(<expr>)
Section intitulée « 3.5 addWhere(<expr>) »- Description: Applies an extra condition that affects only the associated metric calculation, not the entire query.
Example:
SELECT metric('transactions_order_date.billing_ttc', addWhere(dimension('customer_age') BETWEEN 25 AND 35)) AS billing_young_customers, metric('transactions_order_date.billing_ttc') AS billing_all_customers FROM datamodel WHERE refDate BETWEEN '2025-01-01' AND '2025-01-31'5. Simple Examples
Section intitulée « 5. Simple Examples »5.1 Selecting a Single Metric
Section intitulée « 5.1 Selecting a Single Metric » SELECT metric('transactions_order_date.billing_n_orders') AS total_orders FROM datamodel WHERE refDate BETWEEN '2023-07-01' AND '2023-07-31'5.2 Grouping by a Dimension
Section intitulée « 5.2 Grouping by a Dimension » SELECT dimension('product_brand') AS brand, metric('transactions_order_date.billing_n_products') AS product_count FROM datamodel WHERE refDate BETWEEN '2024-01-01' AND '2024-03-31' GROUP BY brand ORDER BY product_count DESC5.3 Time-Series Grouping
Section intitulée « 5.3 Time-Series Grouping » SELECT refDateDimension(INTERVAL 1 DAY) AS date_day, metric('transactions_order_date.billing_with_vat') AS daily_billing FROM datamodel WHERE refDate BETWEEN '2024-02-01' AND '2024-02-28' GROUP BY date_day ORDER BY date_day5.4 Using addWhere to Filter a Specific Metric
Section intitulée « 5.4 Using addWhere to Filter a Specific Metric » SELECT dimension('customer_country') AS customer_country, metric('transactions_order_date.billing_ht') AS billing_total, metric('transactions_order_date.billing_ht', addWhere(dimension('customer_age') BETWEEN 18 AND 25)) AS billing_young_adults FROM datamodel WHERE refDate BETWEEN '2025-01-01' AND '2025-03-31' GROUP BY customer_country ORDER BY billing_total DESC5.5 Overriding the Date Range for One Metric
Section intitulée « 5.5 Overriding the Date Range for One Metric » SELECT metric('transactions_order_date.billing_n_orders') AS current_orders, metric('transactions_order_date.billing_n_orders', overrideRefDate('2024-05-01', '2024-05-31')) AS previous_period_orders FROM datamodel WHERE refDate BETWEEN '2025-05-01' AND '2025-05-31'6. Subqueries, Joins, and QUALIFY
Section intitulée « 6. Subqueries, Joins, and QUALIFY »6.1. Subqueries
Section intitulée « 6.1. Subqueries »You can place a NexusQL query (which selects from datamodel) inside another query to perform post-processing.
In such cases, standard SQL rules apply to the outer query, so you could use standard aggregation functions, HAVING or JOIN clauses, etc
Though most analyses require only one FROM datamodel, you can use standard SQL join syntax between subqueries to perform more
computations.
6.2. Window Functions & QUALIFY clause
Section intitulée « 6.2. Window Functions & QUALIFY clause »Window functions (e.g., ROW_NUMBER() OVER(...), RANK() OVER(...), etc.) and the QUALIFY clause are only supported outside of
FROM datamodel usage.
Typically, you select your data from datamodel in a subquery, then the outer query can apply window functions and/or a QUALIFY filter.
Examples :
SELECT..., RANK() OVER(...)FROM some_subqueryor
SELECT brand, product_name, billing_n_products, ROW_NUMBER() OVER (PARTITION BY brand ORDER BY billing_n_products DESC) AS rank_in_brand FROM ( SELECT dimension('product_brand') AS brand, dimension('product_name') AS product_name, metric('transactions_order_date.billing_n_products') AS billing_n_products FROM datamodel WHERE refDate BETWEEN '2025-01-01' AND '2025-06-30' GROUP BY brand, product_name ) AS sub QUALIFY rank_in_brand <= 5 ORDER BY brand, rank_in_brand7. Additional Notes
Section intitulée « 7. Additional Notes »- Performance: NexusQL leverages a specialized engine behind
datamodel. Ensure yourWHEREclause withrefDate BETWEEN ...is well-defined to utilize optimizations. - Aliasing: In
WHERE,GROUP BY,ORDER BY, you can referencedimensions andrefDateDimensionby their aliases or by reusing the same function calls.
8. Summary
Section intitulée « 8. Summary »NexusQL extends SQL with specialized functions for OLAP-style metrics and dimensions while enforcing:
- A fixed
FROM datamodel. - A mandatory
refDaterange inWHERE. - Grouping all selected dimensions.
- Specialized functions (
metric,dimension,refDateDimension,overrideRefDate,addWhere) tailored to business analytics needs.
For more advanced operations—window functions, QUALIFY, etc.—wrap your primary NexusQL query in an outer query.
Feel free to explore the provided examples to get started quickly, and refer to standard SQL resources for common syntax and operations not outlined here.
9. More advanced queries
Section intitulée « 9. More advanced queries »9.1 ranking & cumulative sum
Section intitulée « 9.1 ranking & cumulative sum »SELECT rank() OVER (ORDER BY billing_n_products desc) AS rank, product_brand, billing_n_products, sum(billing_n_products) OVER (ORDER BY billing_n_products desc) AS billing_n_products_cum_sumFROM (SELECT dimension('product_brand') AS product_brand, metric('transactions_order_date.billing_n_products') AS billing_n_products FROM datamodel WHERE refDate BETWEEN '2024-01-10' AND '2025-01-16' GROUP BY product_brand ) AS t1ORDER BY billing_n_products descLIMIT 109.2 ABC dynamic classification
Section intitulée « 9.2 ABC dynamic classification »SELECT product_id, product_name, SUM(total_ca_ht) OVER () AS global_ca_ht, total_ca_ht, SUM(total_ca_ht) OVER (ORDER BY total_ca_ht DESC) AS cumulative_ca_ht, total_ca_ht / global_ca_ht * 100 AS ca_percentage, cumulative_ca_ht / global_ca_ht * 100 AS cumulative_ca_percentage, CASE WHEN cumulative_ca_percentage <= 80 THEN 'A' WHEN cumulative_ca_percentage <= 95 THEN 'B' ELSE 'C' END AS abc_classificationFROM (SELECT dimension('product_id') AS product_id, dimension('product_name') AS product_name, metric('transactions_order_date.billing_product_ht') AS total_ca_ht FROM datamodel WHERE refDate BETWEEN '2024-01-10' AND '2025-01-16' GROUP BY product_id, product_name ) AS st1ORDER BY total_ca_ht DESC9.3 Cohort
Section intitulée « 9.3 Cohort »SELECT t1.cohort_dimension AS cohort_dimension, t2.main_metric AS main_metric, t1.analysis_dimension AS analysis_dimension, t1.analysis_metric AS analysis_metricFROM ( SELECT dimension('customer_first_order_date') AS cohort_dimension, dateDiff('day',dimension('customer_first_order_date'),refDate) AS analysis_dimension, metric('transactions_order_date.billing_ht') AS analysis_metric FROM datamodel WHERE refDate BETWEEN '2024-01-01' AND '2024-02-09' AND cohort_dimension BETWEEN '2024-01-01' AND '2024-01-31' AND analysis_dimension<10 GROUP BY cohort_dimension,analysis_dimension ) AS t1 LEFT JOIN( SELECT dimension('customer_first_order_date') AS cohort_dimension, count('customers_first_order_date') AS main_metric FROM datamodel WHERE refDate BETWEEN '2024-01-01' AND '2024-01-31' GROUP BY cohort_dimension) AS t2 ON t1.cohort_dimension=t2.cohort_dimensionORDER BY t1.cohort_dimension,t1.analysis_dimensionSELECT dimension('customer_id') AS d0, metric('transactions_order_date.billing_ttc', overrideRefDate('2024-01-01', '2024-12-31'), addWhere(dateDiff('day', dimension('customer_first_order_date'), dimension('transaction_order_date')) BETWEEN 0 AND 180)) AS m0FROM datamodelWHERE refDate BETWEEN '2026-01-01' AND '2026-12-31'GROUP BY d0ORDER BY m0 DESCLIMIT 10