Search code examples
javascriptmysqlcubesanalyticalcube.js

Cube Js | calculate difference between 2 Dates


In cube js finding the count between days is not working for mysql database. Please help me to resolve. While calculating the balance days between....

measures: {
  balanceDays: 
    {
      type: count,
      sql: DATEDIFF(day, '${NmOrder.show_date}', '${NmOrder.booked_date}')   
    },
},

This is also not working

measures: {
      balanceDays: 
        {
          type: count,
          sql: TO_DAYS(${show_date}) - TO_DAYS(${booked_date}) 
        },
    },

Solution

  • Don't need to mention MySQL keywords. Just simply like below

    measures: {
          balanceDays: 
            {
              type: countDistinct,
              sql: show_date - booked_date 
            },
        },