Custom measures in pivot grid

5 posts, 0 answers
  1. Satabdi
    Satabdi avatar
    13 posts
    Member since:
    Aug 2014

    Posted 06 Apr 2015 Link to this post

    Hello

    Can we customize the measure based on some other column values? eg: If I have measures like below,

     measures: {
                                "ChainShare": { field: "ChainShare", aggregate: "sum" },
                                "DemandIndex":{field:"DemandIndex",aggregate: "sum"},
                                "GroupShare":{field:"GroupShare",aggregate: "sum"}
                            }

    Then can we define DemanIndex field as ChainShare/GroupShare .

     

    Thanks and Regards

    Satabdi

  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 08 Apr 2015 Link to this post

    Hello Satabdi,

    In general, the measures use separated scope, which means that the "DemandIndex" measure does not have connection to the other measures. That being said, you will need to calculate "ChainShare" and "GroupShare" in the aggregate function of the "DemandIndex" measure. Basically, you will need to aggregate both related measures in the aggregate function and then calculate the "DemandIndex" measure in the measure's result function.

    Please refer to the schema.cube documentation and more specifically the measures section. All mentioned functions are documented there.

    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. con_ssc
    con_ssc avatar
    87 posts
    Member since:
    Apr 2014

    Posted 12 Jun 2015 in reply to Satabdi Link to this post

    Yes it is possible:

    01.measures: {
    02.    "ChainShare": {
    03.        field: "ChainShare",
    04.        aggregate: "sum"
    05.    },
    06.    "DemandIndex": {
    07.        field: "DemandIndex",
    08.        aggregate: function (value, state, context) { // value is always undefined because DemandIndex does not exsist
    09.                var dataItem = context.dataItem;
    10.                var ChainShare = dataItem.ChainShare;
    11.                var GroupShare = dataItem.GroupShare;
    12. 
    13.                // manual aggregation
    14.                state.ChainShare = ( state.ChainShare || 0 ) + ChainShare;
    15.                state.GroupShare = ( state.GroupShare || 0 ) + GroupShare;
    16.            },
    17.            result: function(state){
    18.                if ( state.ChainShare == 0 || state.GroupShare == 0 ){
    19.                    return 0;
    20.                } else {
    21.                    return (state.ChainShare / state.GroupShare) ;
    22.                }
    23.            }
    24.    },
    25.    "GroupShare": {
    26.        field: "GroupShare",
    27.        aggregate: "sum"
    28.    }
    29.}

  5. Jerome
    Jerome avatar
    1 posts
    Member since:
    Oct 2014

    Posted 20 May Link to this post

    Hello,

    What would be the mvc equivalent to this code ?

    For the aggregate function, it waits a function with an object parameter and an object result...

     

    .Measures(measures =>
                    {
                        measures.Add("Sum").Format("{0:c}").Field(model => model.X)
                            .Aggregate(...); })                      
                    })

  6. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 24 May Link to this post

    Hello Jerome,

    The specific aggregate implementation should be done in JavaScript in both cases. In the context of the ASP.NET MVC wrapper, you will need to define the aggreate/result functions as names like so:
    <script>
     function sum_aggreate(...) { ... }
     function sum_result(...) { ... }
    </script>
    ...
    .Aggregate("sum_aggregate").Result("sum_result");
    ...
     

    Regards,
    Georgi Krustev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready