Retrieving Deltas between two periods

Hello. We are currently trying to display the data for a date range while also displaying the change since the previous period. Something like this:
image

The best solution I could come up with would be to use compareDateRange, query both date ranges and then process the data returned by cube.
However, we’d like to display this data in multiple places and if it not cube returning this data (already processed) we’d need to do this same processing in every implementation where this data is displayed.

Any thoughts on how to calculate this delta on cube?
Thanks

Hi @Bernardo_Bonanca :wave:

Indeed, that’s the best way to implement this with Cube.

It would make sense to make this a separate component in your front-end layer, e.g., a React component if you use React. If will take care of reusing the values throughout the app. Even if not, querying Cube multiple times is definitely not a problem: you should have pre-aggregations defined, so the first query should be fast, and subsequent queries should be served even faster from the in-memory cache.

1 Like

This makes sense. The challenge though is we’ll need to reuse it on different applications/services such as website, emails, etc where a react component cannot be used everywhere.

Thank you for your input Igor. :+1: