1

I have a query like below :

 {
    "measures": [...],
    "dimensions": [],
     "timeDimensions": [
        {
            "dateRange": ["2020-01-03", "2020-31-03"]
        }
     ]
 }

it returns an array of ONE object for example

[{ totalSales : 1234, totalDollar : "1234,56", ...}]

I woud like to compare thoses data with different period over time (client side). So my quesiton is : Is it possible to get the result on multiple time range on single request

for exemple

 {
    "measures": [...],
    "dimensions": [],
     "timeDimensions": [
        {
            "dateRange": ["2020-03-01", "{2020-03-31"]
        },
        {
            "dateRange": ["2020-02-01", "{2020-02-29"]
        }, 
        ...
     ]
 }

and have a result like

[
    { totalSales : 1234, totalDollar : "1234,56", ...},
    { totalSales : 2222, totalDollar : "232323,23", ...},
    ...
] 

Is it possible to do that or i must execute several requests with different time range ?

Thanks

Maxime Girou
  • 1,511
  • 2
  • 16
  • 32
  • Whats your backend? – GBWDev Mar 02 '20 at 16:15
  • @GBWDev it's a cube.js query. https://cube.dev/ – Maxime Girou Mar 02 '20 at 16:16
  • What happens when you try to run the example API call you wrote? docs say `timeDimensions` is an array of objects in timeDimension format - as opposed to a single object. Logic would suggest passing multiple is ok? – GBWDev Mar 02 '20 at 16:21
  • @GBWDev when multiples Objects are passed, it keep return an array wirth a single object. I think it take the intersection of the date ranges. But what i need is separated results for the same query but different time range. I don't even know if it's possible. Just asking – Maxime Girou Mar 02 '20 at 16:23

2 Answers2

2

In newer cube versions you can use compareDateRange instead of dateRange and pass it an array of dateRanges. See https://cube.dev/docs/query-format#time-dimensions-format

1

As for now the simplest way to do it is to perform 2 separate queries. Please see https://github.com/cube-js/cube.js/issues/461

Pavel Tiunov
  • 1,163
  • 6
  • 8