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

Custom measures in pivot grid

4 Answers 691 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Satabdi
Top achievements
Rank 1
Satabdi asked on 06 Apr 2015, 05:10 AM

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

4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 08 Apr 2015, 06:41 AM
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!
 
0
CS
Top achievements
Rank 2
answered on 12 Jun 2015, 10:02 AM

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

0
Jerome
Top achievements
Rank 1
answered on 20 May 2016, 12:57 PM

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(...); })                      
                })

0
Georgi Krustev
Telerik team
answered on 24 May 2016, 08:24 AM
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!
 
Tags
PivotGrid
Asked by
Satabdi
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
CS
Top achievements
Rank 2
Jerome
Top achievements
Rank 1
Share this question
or