jQuery UI Widgets › Forums › Grid › Custom function in PivotGrid with 2 passing parameters
Tagged: #pivotgrid, average, javascript pivotgrid, jquery pivotgrid, jqwidgets pivotgrid, weighted, Weighted average
This topic contains 13 replies, has 5 voices, and was last updated by Hristo 1 year, 5 months ago.

Author

Hello,
I would like to use 2 fields in a custom function in the pivod grid, in order to implement (for example) the weighted average.
Is it possible ?Thank you in advance
VangelisHello Vangelis,
Please, take a look at this demo:
https://www.jqwidgets.com/jquerywidgetsdemo/demos/jqxpivotgrid/pivotgrid_custom_rendering.htm?light
Could you clarify what you want to achieve, if the example above does not help you?Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comHello Hristo,
I saw the example but it is not what I am talking about.
Let’s say we want to have a custom function (like Excel) which is using 2 datafields.
For example the weighted average function with price and quantity fields.
Is it possible to pass 2 datafields in a custom function of the pivotGrid ?
Alternatively I tried to use in my custom function one string field which includes price and quantity seperatated with ‘;’.
The idea was to split inside the custom function the string into 2 arrays so to overcome the problem with one datafield, but it did’t work.
If you have any solution, I’d appreciate to share it with me.Best Regards
VangelisHello Vangelis,
I would like to suggest you look at this rough solution below:
https://www.jqwidgets.com/jseditor/?key=jqxpivotgridcalculationofweightedaverage
You could improve it on your way.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.com This reply was modified 1 year, 7 months ago by Hristo.
Hello Hristo,
Your example shows the flexibility of the pivotGrid.
Thanks again
VangelisCould you solve the problem?
Might you help me
Hello alexanderAyala,
Could you clarify your issue?
It will be better to provide us more details, thanks.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comI’m going to use the weighted average in the Pivot:
A: Note
B: Weight
It is to multiply the column A * B, to that result it is added.
After having that sum it is divided by the sum (B).
So when using functions in the pivot I did not find it to send two variables.
{dataField: ‘pmate’, ‘function’: ‘prom_ponderado’, text: ‘Mathematics’,PromedioPonderado = sum(A*B)/sum(B)
good morning
I have the same question as I use two varibles in the functions
Thanks for the helpHello,
The suggested example in one of the previous post do the same:
https://jseditor.io/?key=jqxpivotgridcalculationofweightedaverage
Or @alexanderayala you have an additional ‘column’ with which the result should be multiplied.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comHi!,
I have the same issue, I need to calculate the percentage variation in two values in one new value column.
I have this:
rows Values–> Dic 2017 Ene 2018 % Var Mes
——————————————————————————————————————
Row 1  1050 2025 ((2025 – 1050)/1050) * 100) = 92%
Row 1.1  1000 2000 ((2000 – 1000)/1000) * 100 = 100%
Row 1.1.1 
Row 1.2  50 25 ((25 – 50)/50) * 100) = 50%
Row 2 
Row 2.1 
Row 2.2 
Row 2.3 
Row 2…. 
+Row 3 
+Row 4 I need to calculate ( [% Var Mes] = Sum([Ene 2018]) – Sum([Dic 2017]) / Sum([Dic 2017]) ), but the SUM is the SUM of each row aggregated.
I DONT HAVE COLUMNS! ONLY VALUES! –>
columns: [],
values: JSON_DataValuesSorry for my bad english I hope you understand,Thanks for the help
Hello carloshv700,
The example that I suggest demonstrates how to get specific row and column.
With this information, you could get a value of a concrete cell –.getCellValue(specificRow, specificColumn);
Could you clarify your scenario? What means “Row 1, Row 1.1, Row 2, Row 2.1” is this the inner items or it is something like jqxTreeGrid?
Also, it looks like this information could be represented in jqxGrid.I think for your case it is possible to use
beforeLoadComplete
callback of the DataAdapter to calculate the additional item in rows.
Please, take a look at this example.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.com 
AuthorPosts
You must be logged in to reply to this topic.