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?

In your custom method you are always returning the “1”, so this value is displaying for your cell values and footer.
You need count all the unique values in your “cellValue” parameter.
For example it can be done with the following code: (note that in your case the correct value will be 5, not 4, as “0” is also a unique value)