The cube query#
The cube query is the JSON body sent to the query API, which the MCP server also uses. It describes the same thing that is chosen in the cube viewer: which dimensions go in rows and columns, which metrics are calculated and with which segmentation. This page is its reference, with the extensions that only exist in the API: comparing periods, calculated metrics, compound queries and the others.
Before you start#
First read the walkthrough of the Query API. All identifiers (of dimensions, metrics, lists and tables) come from the connection's catalog: in the examples they are made up.
The basic form#
{
"rows": [
{ "dimension": 310, "dateLevel": "YEAR", "sort": { "by": "CODE" } },
{ "dimension": 305, "sort": { "by": "RANKING", "metric": 0, "descending": true },
"filter": { "mode": "FIRST_N", "count": 5 } }
],
"columns": [],
"metrics": [ { "metric": 1201 }, { "metric": 1201, "display": "PERCENT_OF_TOTAL" } ],
"segmentation": { "root": { "type": "group", "logic": "AND", "children": [
{ "type": "condition", "dimension": 305, "operator": "IN",
"values": [ { "type": "literal", "value": "N" }, { "type": "literal", "value": "C" } ] } ] } },
"totals": false
}
This query asks for the total amount and its percentage of the total, per year and, within each year, of the five zones that invoice the most, only with the North and Center zones.
| Field | What it is |
|---|---|
rows, columns |
The dimensions of the axes, in order (below). The output is always long; the columns matter for the percentages by row or column and for the cumulative values. |
metrics |
The metrics, by their id, with their display. |
segmentation |
The filters applied in the database, before aggregating. |
totals |
true adds the total and subtotal rows. |
listing |
true requests a listing: one row per record, without metrics (only rows). |
from |
A starting document (below). |
comparison, parts, order |
The extensions: comparing periods, compound queries and the order of the output. |
Limits: at most 20 dimensions and 50 metrics. The cube rules are checked on receiving the query: at least one metric (except in a listing), each dimension on a single axis, rankings on a metric of the list… What does not follow them is 400 INVALID_QUERY with the problem.
A field of an axis#
| Field | Values | What it does |
|---|---|---|
dimension |
An id from the catalog |
The dimension |
dateLevel |
YEAR, SEMESTER, QUARTER, MONTH, WEEK |
Groups a date dimension at that level |
showTotals |
true (default) or false |
Whether it carries a subtotal with totals: true |
sort |
{ "by": "LABEL" } (default), CODE, NONE or RANKING with metric (position in metrics, from 0) and descending |
The order of its members |
filter |
FIRST_N or LAST_N with count; SELECTION with keys; FROM_DATE, TO_DATE or BETWEEN_DATES |
A filter in memory, after calculating, like the viewer's |
A metric#
| Field | What it does |
|---|---|
metric |
The metric's id. formula or aggregate can go in its place (below). |
display |
The display: VALUE (default), PERCENT_OF_TOTAL, PERCENT_OF_ROW, PERCENT_OF_COLUMN, PERCENT_OF_GROUP and PERCENT_OF_GROUP_TOTAL (with groupDimension), CUMULATIVE_ROWS and CUMULATIVE_COLUMNS (cumulative), CUMULATIVE_PERCENT_ROWS and CUMULATIVE_PERCENT_COLUMNS (cumulative %) and MOVING_AVERAGE_ROWS and MOVING_AVERAGE_COLUMNS (moving average, with period). |
groupDimension |
The group dimension of the group percentages and cumulative values. |
totalType |
How its total is calculated: NONE, SUM, COUNT, AVG, WEIGHTED_AVG, MIN, MAX, CALCULATED (recalculates the expression on the totals), INCREASE_ROWS or INCREASE_COLUMNS (% increase between the first and the last value). |
period |
The lines of a moving average, from 1 to 1000. |
name, format |
The column's name and its mask, as when renaming in the viewer. |
Percentages are given from 0 to 100 and are calculated on the query's rows, after the segmentation and the universes.
The segmentation#
segmentation.root is a tree of groups ("type": "group", with logic AND, OR, NOT_AND or NOT_OR, and NOT_EXISTS, below) and conditions. It is the same model as the application's segmentation editor.
Condition on a dimension:
{ "type": "condition", "dimension": 310, "operator": "BETWEEN",
"ranges": [ { "from": { "type": "literal", "value": "2025-01-01" },
"to": { "type": "literal", "value": "2025-12-31" } } ] }
operator:EQUAL,NOT_EQUAL,GREATER,LESS,GREATER_OR_EQUAL,LESS_OR_EQUAL,LIKE,NOT_LIKE,IN,NOT_IN,BETWEEN,NOT_BETWEEN,IS_NULLandIS_NOT_NULL.- Values:
literal(a text, a number with a decimal point or an ISO date),tuple(the codes of a dimension with a compound key,codeLengthgreater than 1) ordynamicDate, a relative date:{ "type": "dynamicDate", "anchor": "START_OF_YEAR", "offset": -1, "offsetUnit": "YEARS" }. The anchors areSTART_OF_andEND_OF_withYEAR,SEMESTER,QUARTER,MONTH,WEEKandDAY, andNOW; the units,YEARS,MONTHS,WEEKS,DAYS,HOURS,MINUTESandSECONDS. - The codes of a lookup come from the dimension's members: do not make them up.
A list includes or excludes the records of a list from the catalog: { "type": "list", "factTable": 2, "list": 7, "include": true }.
A condition on a metric filters the already aggregated rows (each combination of the axes), not the records: it is the editor's HAVING.
{ "type": "metricCondition", "metric": 1201, "operator": "GREATER",
"values": [ { "type": "literal", "value": "1000" } ] }
It accepts numbers, without LIKE; it goes with AND to the rest of the segmentation, and its metric has to belong to the table of the query's first metric. A listing does not accept them.
A grouping is used like any dimension, with the codes of its buckets as literals ("value": "1") and only with EQUAL, NOT_EQUAL, IN and NOT_IN.
Tip
Segmentation and filter are not the same. Segmentation filters in the database and changes the totals; the filter of a field (first N, selection, dates) is applied after calculating, as in the viewer.
Start from a document (from)#
{ "from": { "workbook": "5b0e…", "document": "c1f7…", "bookmark": "9a2d…" },
"rows": [ { "dimension": 310, "dateLevel": "YEAR" } ],
"segmentation": { "root": { "type": "group", "logic": "AND", "children": [ … ] } } }
The starting query is the document's (the identifiers come from GET /workbooks), restricted to what the holder sees and trimmed to their data. What the request brings changes it like this:
rows,columnsandmetrics, if they are not empty, replace those of the document.segmentationis added with AND to that of the document's section and to that of the bookmark.- The document has to belong to the route's connection; one that does not exist or that the holder cannot open is
404 NOT_FOUND. - What the document uses and the holder does not see is removed and counted in
hidden. Validating also returnsnormalized: the query already merged with the document's.
The query extensions#
These extensions calculate in ECenter what is not in the catalog. Some also exist in the cube viewer (the cumulative %, the moving average, the week and calculated metrics); others, such as comparing periods or compound queries, only in the API and in the MCP server.
Compare periods (comparison)#
The value of each metric in a current period and in a reference one, with the difference and the % change, by the query's dimensions: “this year compared with the same period last year, by zone”.
{ "rows": [ { "dimension": 305 } ],
"metrics": [ { "metric": 1201 } ],
"comparison": {
"dimension": 310,
"current": { "from": { "type": "dynamicDate", "anchor": "START_OF_YEAR", "offset": 0, "offsetUnit": "YEARS" },
"to": { "type": "dynamicDate", "anchor": "END_OF_DAY", "offset": 0, "offsetUnit": "DAYS" } },
"reference": { "shift": "PREVIOUS_YEAR" },
"show": [ "CURRENT", "REFERENCE", "DIFFERENCE", "PERCENT_CHANGE" ] },
"order": { "metric": 0, "show": "PERCENT_CHANGE", "descending": true, "limit": 5 } }
| Field | What it is |
|---|---|
dimension |
A date dimension the holder sees. |
current |
The current period: from and to, both included, with ISO dates or dynamic dates. |
reference |
The reference one: from and to, or shift: PREVIOUS_YEAR (twelve months earlier) or PREVIOUS_PERIOD (the same duration just before). |
show |
The columns of each metric, in that order: CURRENT, REFERENCE, DIFFERENCE (current minus reference) and PERCENT_CHANGE. Without it, all four. |
Rules:
- It is calculated as two queries, one per period, and they are joined by the members. A row that is only in one period carries the other one empty, and the difference and the % empty. The % is empty if the reference is 0.
- No rankings or first N on the axes: it is sorted and limited with
order. The metrics, with their value (displayVALUE). - The comparison's date dimension can go on an axis only at the
SEMESTER,QUARTERorMONTHlevel (“by month, 2026 compared with 2025”). - It does not accept
listingorparts. - The server names the columns in Spanish: “Importe total (periodo actual)” (current period), “(periodo de referencia)” (reference period), “(diferencia)” (difference) and “(% de variación)” (% change), and they carry the
comparisonfield. - The explanation states the two periods as dates: “… del 01/01/2026 al 15/10/2026 frente al del 01/01/2025 al 15/10/2025” (from … to …, compared with from … to …).
Calculated metrics (formula)#
A metric that does not exist in the catalog, calculated with others: “average amount per customer”, “% of open incidents”.
"metrics": [
{ "metric": 1201 },
{ "formula": "{M:1201} / {M:1210}", "name": "Importe medio por cliente", "format": "#.##0,00" } ]
- The formula uses
{M:<id>}of catalog metrics,+ - * /, parentheses, numbers with a decimal point andLEVEL({M:<id>}, n). It cannot cite another calculated metric. - It is evaluated cell by cell and, in the totals, on the totals. A division by zero leaves the cell empty.
- The metrics it cites and the query does not request are calculated without being shown, but they count as requested: if any is hidden,
403 COLUMNS_HIDDEN. They have to be able to go together (metricTablesof the catalog). - Without
name, the column is named like the formula with the names of its metrics; withoutformat,#.##0,00.
Aggregation of a dimension (aggregate)#
The sum, the average, the minimum or the maximum of a numeric dimension: “the average age of the customers”.
function:SUM,AVG,MINorMAX.- The dimension has to be numeric (
NUMERIC), visible, and not a lookup, a grouping or a date level. - Without
name, the column is named “Edad (media)”, “(suma)”, “(mínimo)” or “(máximo)” (average, sum, minimum, maximum; the server writes them in Spanish). Only in the API and the MCP.
The week (WEEK)#
"dateLevel": "WEEK" groups by the ISO week with its year: code 202641, label 2026-W41. Unlike the semester, the quarter or the month, it does not merge different years. “The last 12 weeks” is the date at the WEEK level on an axis and the condition date ≥ { "type": "dynamicDate", "anchor": "START_OF_WEEK", "offset": -11, "offsetUnit": "WEEKS" }.
Cumulative % and moving average#
{ "metric": 1201, "display": "CUMULATIVE_PERCENT_ROWS" }
{ "metric": 1201, "display": "MOVING_AVERAGE_ROWS", "period": 3 }
- The cumulative % (the Pareto) is the cumulative value as a % of its group's total. It makes sense with the dimension sorted by the metric from highest to lowest.
- The moving average averages the previous
periodlines of its group, including the cell's. Withoutperiod,400. - Both accept
groupDimensionand the_COLUMNSvariant, towards the right.
“No records” (NOT_EXISTS)#
“The customers who have not bought in 2026”: a segmentation group that requires that no record of a table meet its conditions.
{ "type": "group", "logic": "NOT_EXISTS", "factTable": 2, "children": [
{ "type": "condition", "dimension": 310, "operator": "GREATER_OR_EQUAL",
"values": [ { "type": "literal", "value": "2026-01-01" } ] } ] }
- The child conditions are joined with AND; without children, “no record”.
- The table has to be a detail table of the query (its path from the query's tables goes down to the “many” side of a relation). If not,
400 INVALID_QUERY. - It is not the same as negating a group, which asks for “some record that does not meet it”.
Compound query (parts)#
Metrics of fact tables that do not combine, joined by a common dimension: “sales against target by sales rep”.
{ "parts": [
{ "rows": [ { "dimension": 412 } ], "metrics": [ { "metric": 1201 } ] },
{ "rows": [ { "dimension": 530 } ], "metrics": [ { "metric": 1301 } ] } ],
"metrics": [ { "formula": "{M:1201} * 100 / {M:1301}", "name": "Cumplimiento (%)", "format": "0,00" } ],
"totals": true,
"order": { "metric": 2, "descending": false, "limit": 10 } }
- From 2 to 4 parts. Each one is a query with its axes, its metrics and its segmentation (and, if wanted, its
from), without rankings or first N, and with the same number of dimensions in rows and in columns as the others. A metric goes in a single part. - Dimension
iof each part is paired with dimensioniof the first by the code of its members: the same dimension or two with the samelookupTableof the catalog, with the same date level. - At the top only
metrics(only formulas on the parts' metrics, withoutLEVEL),totalsandordergo. - The rows are the union: first those of the first part; a row that is only in one part lacks the metrics of the others. The columns of each part carry
queryPart(from 0).
The order of the output (order)#
Only with comparison or parts: it sorts the data rows of the whole output and keeps the first ones.
| Field | What it is |
|---|---|
metric |
The position of the metric in the output, from 0. With parts: those of the first part, those of the second… and finally the calculated ones. |
show |
With a comparison, the column by which it is sorted (CURRENT if missing). |
descending |
From highest to lowest. |
limit |
The rows kept, from 1 to 10,000. |
Empty rows go at the end and total rows do not change: they go after the data rows.
The output#
Each dimension gives a CODE column per column of its key (which is valid as is in a condition) and, if it is a lookup, another LABEL column with its description. Each metric gives a METRIC column with its unformatted value and its mask in format. The extensions add period, formula, aggregate, comparison or queryPart to their columns. The types are NUMBER, TEXT, DATE, DATETIME, BOOLEAN and IDS; dates, in ISO 8601. The download formats are explained in Results, limits and errors.