COUNT measure

5 posts, 0 answers
  1. Juliana
    Juliana avatar
    8 posts
    Member since:
    Jul 2015

    Posted 05 Aug 2015 Link to this post

    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? 

  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 06 Aug 2015 Link to this post

    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!
     
     
  3. Kendo UI is VS 2017 Ready
  4. Juliana
    Juliana avatar
    8 posts
    Member since:
    Jul 2015

    Posted 07 Aug 2015 in reply to Georgi Krustev Link to this post

    #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?

  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 11 Aug 2015 Link to this post

    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!
     
  6. Jorrit
    Jorrit avatar
    2 posts
    Member since:
    May 2016

    Posted 01 Jun in reply to Georgi Krustev Link to this post

    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
                }
          }
     }

     

Back to Top
Kendo UI is VS 2017 Ready