Author Topic: Grand Summary adding in Group summaries  (Read 2814 times)

MEngelbyPQ

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 21
    • View Profile
Grand Summary adding in Group summaries
« on: May 02, 2018, 01:07:23 am »
Greetings!

I've run into something that I can't figure out how to correct.

Given this grid, https://plnkr.co/edit/CmjcHCV4OcSftwV2mqu5?p=preview, grouping has been turned on with summaries being shown at the bottom of the group.
While the group summaries are correct, the Grand Summary in the last row appears to add the group summary total twice.  The effect seen is the group detail lines are totaled then multiplied by 3.
If a person comments out the summary options in the colModel (script.js lines 32, 35, and 40), the Grand Summary computes correctly.

In the summaryData option, is there a way to alter the summing function 'sum(C:C), etc' to ignore the group summing rows?

-Mike

mercury85

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 58
  • ASP.NET, VB.NET, MVC, JS, C#, VBA, SQL, MDX, DAX
    • View Profile
Re: Grand Summary adding in Group summaries
« Reply #1 on: May 02, 2018, 10:11:10 am »
Hey Mengel,

Your formula is the array of the column itself,  pq_fn: {revenues:'sum(C:C)', profits:'sum(D:D)', diff:'sum(E:E)'

Had a similar issue the other day, resolved it using a javascript formula, looking at what your trying to do.

https://plnkr.co/edit/2P5W0d3zHfm2ytI9PL0C?p=preview

After reviewing with ParamQuery, we ended up using formulas to control the summation. 

    function calculateSummary() {
       

if your trying to get the summary of your data pulled in you could use the following:
     
        grid = pq.grid("#grid_summary");
   
                   
                    var data = grid.options.dataModel.data;
                 
                 
                    if (data.length > 0)
                    {
                        var totalSumProfit = 0;
                        var totalSumRevenue = 0;
                        for (var i = 0, len = data.length; i < len; i++) {
                            var rowData = data;
                            totalSumProfit += parseFloat(rowData["profits"]);
                            totalSumRevenue += parseFloat(rowData["revenues"]);
                        }
                       
                       
                       alert(totalSumProfit);
                       alert(totalSumRevenue);
                       
                    }
                }


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Grand Summary adding in Group summaries
« Reply #2 on: May 02, 2018, 10:40:20 am »
Thanks for sharing plnkr.

There is no need for a separate summaryData option, Excel formulas or manual calculation when grouping is on.

Instead of summaryData option, just add grandSummary: true to the groupModel ( which is simple, easy and recommended )

https://plnkr.co/edit/918crtEDcI98Y5Yt

Online example: https://paramquery.com/pro/demos/group_summary
« Last Edit: May 02, 2018, 10:44:59 am by paramquery »

MEngelbyPQ

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Grand Summary adding in Group summaries
« Reply #3 on: May 02, 2018, 12:51:49 pm »
Thanks for the suggestion mgregory85.  That was one of my attempted fixes.  It works well until one uses the filtering option.  There doesn't seem to be a way to identify rows that are filtered out.

That's what I needed ParamQuery.  Thank you.
Took me a bit to figure out how to get the grand summary row to look like it was previously.
I added a rowInit conditional to check for the key 'pq_grandsummary' and changed the content of the company cell.

Here is my latest iteration;  https://plnkr.co/edit/9I7q9uJwnbnFTQdZ090W?p=preview