PivotGrid Custom measures for subtotal

0 Answers 95 Views
PivotGrid
james
Top achievements
Rank 1
james asked on 14 Sep 2023, 04:09 AM

Hi 

I need create one measure for total sales amount Proportion by product category. For Example:

column                                    measure

Productcate ,  Productname  salesamount   amount%

A, A1               100,       58%

A, A2                50       29%

A, A3                 20    11%

A subtotal       170    73%

B, B1                 50    83%

B, B2                  10  17%

b subtotal       60    27%

Total               230  100%

 

How to design this code function?

Thanks.

James

 

Nikolay
Telerik team
commented on 18 Sep 2023, 01:39 PM

Hi James,

You can check the following four thread discussing the same topic:

https://www.telerik.com/forums/custom-measures-in-pivot-grid

https://www.telerik.com/forums/calculate-measures-in-a-pivotgrid

Regards,

Nikolay

james
Top achievements
Rank 1
commented on 28 Sep 2023, 03:46 AM | edited

Hi Nikolay,

Thanks for your help first. Could you please get me custom measure detail documents? Because we don't know how to set this sample.

.Aggregate("aggregateHandler").Result("resultHandler")

In my case calculate the sales-total values by  column group. It is different from fields detail data. 

 
Please kindly help this. Thanks

Regards,

James

Nikolay
Telerik team
commented on 02 Oct 2023, 01:45 PM

Hi,

The relevant configuration of the Html Helper

.Aggregate("aggregateHandler").Result("resultHandler")

if the following:

                                 measures: {
                                    "Anzahl": { field: "G30_KEY", aggregate: "sum" },
                                    "Gewicht": { field: "G30_SACH_RECHTSGEBIET", aggregate: "sum" },
                                    "Ratio": {
                                       field: "G30_SACH_RECHTSGEBIET",
                                        aggregate: function (value, state, context) {
                                            var dataItem = context.dataItem;
                                            var G30_SACH_RECHTSGEBIET = dataItem.G30_SACH_RECHTSGEBIET;
                                          	var G30_KEY = dataItem.G30_KEY;
                                            
                                            // Manually aggregate the fields.
                                            state.G30_SACH_RECHTSGEBIET_SUM = ( state.G30_SACH_RECHTSGEBIET_SUM || 0 ) + G30_SACH_RECHTSGEBIET;
                                          
                                          	state.G30_KEY_SUM = ( state.G30_KEY_SUM || 0 ) + G30_KEY;
                                        },
                                         result: function (state) {
                                             return (state.G30_SACH_RECHTSGEBIET_SUM / state.G30_KEY_SUM).toFixed(2);
                                         }
                                    }
                                }

Here is the runnable DOjo: https://dojo.telerik.com/ihegiqUq

Regards,

Nikolay

No answers yet. Maybe you can help?

Tags
PivotGrid
Asked by
james
Top achievements
Rank 1
Share this question
or