This is a migrated thread and some comments may be shown as answers.

COUNT measure

4 Answers 345 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Juliana
Top achievements
Rank 1
Juliana asked on 05 Aug 2015, 12:42 PM

Does the count measure count the itens using DISTINCT?

For instance, let's say we have a dataSource like this:

 

var dados = [{ PersonID: 2958, Address: "5h St"},{ PersonID: 2958, Address: "​Lexington Ave"},{ PersonID: 2958, ​Address: "76th Street"}]

 

Note that it is only 1 person, which has 3 address.. if I wanted to use the COUNT measure on the Address, it is correct (it counts 3 itens). But when I use the COUNT measure on the PersonID, it also counts 3 itens, but there is only one personID. If the COUNT measure does not use DISTINCT, Is there any workaround for this? 

4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 06 Aug 2015, 09:47 AM
Hello Juliana,

In general, the widget has a built-in "count" measure that will count the occurrences of the defined field in a particular data slice (based on the rows/columns configuration). If you would like to implement a more sophisticated measures, then you can define a custom aggregate function: Please examine the schema.cube.measures.measureName.aggregate and schema.cube.measures.measureName.result fields. The first one can be used ot aggregate the value for the current data slice.

If you need to access the current rows and columns dimensions, I would suggest you use the PivotDataSource columns and rows methods.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
 
0
Juliana
Top achievements
Rank 1
answered on 07 Aug 2015, 08:12 PM

#1 - Do you plan on developing a built-in "count" distinct measure in the future?

I saw the documentation you linked and I don't understand these two objects: state, context.

#2 - Could you give a more detailed explanation about them? When I try to return the context it only returns Object object;

#3 - I've seen that you're using state.accumulator​ to store the value.. Is there any way to use the state to store an array of values?

0
Boyan Dimitrov
Telerik team
answered on 11 Aug 2015, 03:28 PM

Hello Juliana,

Straight to your questions: 

   1. Currently such feature is not in our to-do list, but you can submit this as a feature request on UserVoice, so that it is considered for implementation in a future release.

   2. The context contains the context for the current aggregate call. It includes the current data item and its index in the data. For some complex calculations you might need not only the value, but some other values from the model object. In those cases you can access the dataItem and extract the required values.

3. The state stores the current aggregated result of the function for already processed records. Also the state uses a predefined field named accumulator, where the last aggregated result is preserved. You can use it to store any kind of values including array of values. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jorrit
Top achievements
Rank 1
answered on 01 Jun 2016, 11:49 AM

I wrote a function which will make a count distinct on the values:

function CountDistinctAggregate(value, state, context)
{
    if (!state.distinctList) {
        state.distinctList = new Array();
    }
    if ($.inArray(value, state.distinctList) < 0) {
        state.distinctList.push(value);
        return (state.accumulator || 0) + 1;
    }
    else {
        return (state.accumulator || 0);
    }
}

To be used like this:

schema: {
    cube: {
        measures: {
            "Nr of unique clients": {
                field: "Client_id", aggregate: CountDistinctAggregate
            }
      }
 }

 

Tags
PivotGrid
Asked by
Juliana
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Juliana
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Jorrit
Top achievements
Rank 1
Share this question
or