Skip to main content

Use case

We’d like to calculate the internal rate of return (XIRR) for a schedule of cash flows that is not necessarily periodic.

Data modeling

XIRR calculation is enabled by the XIRR function, implemented in SQL API and DAX API. It means that queries to any of these APIs can use the this function. The XIRR function is also implemented in Cube Store, meaning that queries to the SQL API or the REST (JSON) API that hit pre-aggregations can also use this function. That function would need to be used in a measure that makes use of multi-stage calculations.
Consequently, queries that don’t hit pre-aggregations would fail with the following error: function xirr(numeric, date) does not exist.
Multi-stage calculations are powered by Tesseract, the next-generation data modeling engine. Tesseract is currently in preview. Use the CUBEJS_TESSERACT_SQL_PLANNER environment variable to enable it.
Consider the following data model:

Query

DAX API

You can use the XIRR function in DAX.

SQL API

Query with post-processing in the SQL API:
Regular query in the SQL API that hits a pre-aggregation in Cube Store:

Result

All queries above would yield the same result: