@@ -272,21 +272,51 @@ GROUP BY 1, 2;
272272### Compare date range query
273273
274274** Compare date range queries are special cases of regular queries.**
275- Similarly to [ regular queries] ( #regular-queries ) , they include lists of
275+ Similarly to [ regular queries] ( #regular-query ) , they include lists of
276276dimensions and measures, filters, etc. and return a result set.
277277
278278However, unlike regular queries, they provide a convenient way to retrieve
279- measure values for * more than one date range* for a time dimension. See [ this
280- blog post] [ blog-compare-date-range ] for more details and examples.
279+ measure values for * more than one date range* for a time dimension.
281280
282281You can make a compare date range query by using the ` compareDateRange `
283- option with the [ REST API] [ ref-rest-api-query-format-options-tdf ] . For the SQL
284- API, you can write an equivalent query using the ` UNION ALL ` statement.
282+ option with the [ REST API] [ ref-rest-api-query-format-options-tdf ] . Note that
283+ you also need to set the ` queryType ` parameter of the [ ` /v1/load `
284+ endpoint] [ ref-rest-api-load ] to ` regular ` .
285+
286+ #### Example
287+
288+ ``` json
289+ {
290+ "dimensions" : [" orders.city" ],
291+ "measures" : [" orders.amount" ],
292+ "filters" : [
293+ {
294+ "member" : " orders.status" ,
295+ "operator" : " equals" ,
296+ "values" : [" shipped" ]
297+ }
298+ ],
299+ "timeDimensions" : [{
300+ "dimension" : " orders.created_at" ,
301+ "compareDateRange" : [
302+ [" 2024-01-01" , " 2024-12-31" ],
303+ [" 2023-01-01" , " 2023-12-31" ],
304+ [" 2022-01-01" , " 2022-12-31" ],
305+ ],
306+ "granularity" : " year" ,
307+ }],
308+ "limit" : 100
309+ }
310+ ```
311+
312+ See [ this blog post] [ blog-compare-date-range ] for more details and examples.
313+
314+ For the SQL API, you can write an equivalent query using the ` UNION ALL ` statement.
285315
286316### Total query
287317
288318** Total queries are special cases of regular queries.**
289- Similarly to [ regular queries] ( #regular-queries ) , they include lists of
319+ Similarly to [ regular queries] ( #regular-query ) , they include lists of
290320dimensions and measures, filters, etc. and return a result set.
291321
292322In addition to that, they provide a convenient way to retrieve the total number
@@ -300,7 +330,7 @@ equivalent query using the `UNION ALL` statement.
300330
301331### Ungrouped query
302332
303- Similarly to [ regular queries] ( #regular-queries ) , ungrouped queries include
333+ Similarly to [ regular queries] ( #regular-query ) , ungrouped queries include
304334lists of dimensions and measures, filters, etc. and return a result set.
305335
306336However, unlike for regular queries, Cube will not add the
@@ -329,6 +359,7 @@ Additionally, note that ungrouped queries have additional requirements for
329359[ ref-apis ] : /product/apis-integrations
330360[ ref-sql-api ] : /product/apis-integrations/sql-api
331361[ ref-rest-api ] : /product/apis-integrations/rest-api
362+ [ ref-rest-api-load ] : /reference/rest-api#v1load
332363[ ref-graphql-api ] : /product/apis-integrations/graphql-api
333364[ ref-data-sources ] : /product/configuration/data-sources
334365[ ref-rest-api-query-format-options ] : /product/apis-integrations/rest-api/query-format#query-properties
@@ -343,4 +374,4 @@ Additionally, note that ungrouped queries have additional requirements for
343374[ ref-caching ] : /product/caching
344375[ ref-query-rewrite ] : /reference/configuration/config#query_rewrite
345376[ ref-ref-sql-api ] : /reference/sql-api
346- [ blog-compare-date-range ] : https://cube.dev/blog/comparing-data-over-different-time-periods
377+ [ blog-compare-date-range ] : https://cube.dev/blog/comparing-data-over-different-time-periods
0 commit comments