Adding Custom function to DHTMLX Pivot


I’m using Dhtmlx pivot, and I don’t manage to succeed in adding

a custom operation to the Pivot.

the pivot comes with - 4 - builtin operations:

  1. Sum
  2. Min
  3. Max
  4. Count

I need a unique Count operation, basically like Count, but it

should only count Distinct values.

this is what I tried, I added this function to the pivot object:

pivot.addMathMethod("uniqueCount", "uniqueCount", (cellData) => {
    if(cellData.length > 0){return (1).toFixed(0) ;}

you can paste these statements to this , Demo

I want to get, for example, the number - 4 - in the first Oil

column for the ‘Constitutional monarchy’ in the pivot, but instead, I

get all - 1 - numbers.

what should I do to accomplish this?