8 Replies Latest reply on Jul 16, 2010 12:40 PM by VRPDeveloper

    AdvancedDataGrid Summary Row Max Function

    mattp22

      I am trying to mix summary function within an advanced data grid.   I'm trying to use the SUM function at the highest grouping level (Southwest).  And a MAX function at the sub regional level (Arizona, Central California, etc).    I want the SUM function at the Southwest level to add the results of the MAX functions from the sub regional level.   Is this possible?

       

      ex.JPG

        • 1. Re: AdvancedDataGrid Summary Row Max Function
          VRPDeveloper

          You can do something like this in order to get SUM function

           

          <!--  The grid -->
              <mx:AdvancedDataGrid  id="adg"
                      width="100%" height="100%">


                  <!-- Define grouping in dataProvider  -->
                  <mx:dataProvider>
                      <!-- Convert flat data to group  -->
                      <mx:GroupingCollection  id="gc"
                              source="{svc.getOrders.lastResult}">

                          <mx:Grouping>
                              <!-- First group by customer -->
                              <mx:GroupingField name="CUSTOMER">
                                  <!-- Calculate total per customer  -->
                                  <mx:SummaryRow summaryPlacement="group">
                                      <mx:fields>
                                          <mx:SummaryField dataField="PRICE"
                                                          operation="SUM"
                                                          label="Total"/>

                                      </mx:fields>
                                  </mx:SummaryRow>
                              </mx:GroupingField>
                              <!-- Then group by orderid -->
                              <mx:GroupingField name="ORDERID">
                                  <!-- Calculate total per orderid  -->
                                  <mx:SummaryRow summaryPlacement="group">
                                      <mx:fields>
                                          <mx:SummaryField dataField="PRICE"
                                                          operation="SUM"
                                                          label="Total"/>

                                      </mx:fields>
                                  </mx:SummaryRow>
                              </mx:GroupingField>
                          </mx:Grouping>
                      </mx:GroupingCollection>
                  </mx:dataProvider>

                  <!-- The grid columns-->
                  <mx:columns>
                      <!-- Empty colume for tree -->
                      <mx:AdvancedDataGridColumn />
                      <!-- Query columns -->
                      <mx:AdvancedDataGridColumn  dataField="CUSTOMER"
                          headerText="Customer" />

                      <mx:AdvancedDataGridColumn  dataField="ORDERID"
                          headerText="Order"/>

                      <mx:AdvancedDataGridColumn  dataField="ARTNAME"
                          headerText="Item" />

                      <mx:AdvancedDataGridColumn  dataField="PRICE"
                          headerText="Price" textAlign="right" />

                      <!-- Column for calculated totals  -->
                      <mx:AdvancedDataGridColumn  dataField="Total"
                          headerText="Total" textAlign="right" />

                  </mx:columns>

              </mx:AdvancedDataGrid>

          • 2. Re: AdvancedDataGrid Summary Row Max Function
            mattp22 Level 1

            I have tried your solution and the sum function works as expected, however it doesn't solve my particular problem.   I would like to get the maxium order total by customer. 

             

             

            I changed the summary field for total per customer to max

             

             

             

            <mx:SummaryField dataField="PRICE"

            operation="

            MAX"

            label="

            Total"/>

             

            Below is the result of this code change.   The value for Cust1 is 20 because that is the max of the part items.  I would like the value to be the maximum at the order level resulting in 30 not 20.

            ex1.JPG

             

            Thanks,

            Matt

            • 3. Re: AdvancedDataGrid Summary Row Max Function
              VRPDeveloper Level 3

              For Maximum u can do in this way

               

               <mx:AdvancedDataGrid id="myADG" 
                      width="100%" height="100%"
                      initialize="gc.refresh();">       
                      <mx:dataProvider>
                          <mx:GroupingCollection id="gc" source="{dpFlat}">
                              <mx:Grouping>
                                  <mx:GroupingField name="Region">
                                      <mx:summaries>
                                        <mx:SummaryRow summaryPlacement="group">
                                          <mx:fields>
                                              <mx:SummaryField dataField="Actual"
                                                  label="Min Actual" operation="MIN"/>
                                              <mx:SummaryField dataField="Actual"
                                                  label="Max Actual" operation="MAX"/>
                                          </mx:fields>
                                        </mx:SummaryRow>
                                      </mx:summaries>
                                  </mx:GroupingField>
                                  <mx:GroupingField name="Territory">
                                      <mx:summaries>
                                        <mx:SummaryRow summaryPlacement="group">
                                          <mx:fields>
                                              <mx:SummaryField dataField="Actual"
                                                  label="Min Actual" operation="MIN"/>
                                              <mx:SummaryField dataField="Actual"
                                                  label="Max Actual" operation="MAX"/>
                                          </mx:fields>
                                        </mx:SummaryRow>
                                      </mx:summaries>
                                  </mx:GroupingField>
                              </mx:Grouping>
                          </mx:GroupingCollection>
                      </mx:dataProvider>       
                     
                      <mx:columns>
                          <mx:AdvancedDataGridColumn dataField="Region"/>
                          <mx:AdvancedDataGridColumn dataField="Territory_Rep"
                              headerText="Territory Rep"/>
                          <mx:AdvancedDataGridColumn dataField="Actual"/>
                          <mx:AdvancedDataGridColumn dataField="Estimate"/>
                          <mx:AdvancedDataGridColumn dataField="Min Actual"/>
                          <mx:AdvancedDataGridColumn dataField="Max Actual"/>
                      </mx:columns>
                 </mx:AdvancedDataGrid>


              If this post answers your question or helps, please kindly mark it as such.
              • 4. Re: AdvancedDataGrid Summary Row Max Function
                mattp22 Level 1

                That is still not the correct solution to my problem.

                 

                What I'm after is a sum at the order level and then a max function at the customer level.   So total the order and then take the max of the orders  not the individual items.    The default max function returns 20 and that is not correct.  I want the value to be 30 which is the maximum of the order total.

                • 5. Re: AdvancedDataGrid Summary Row Max Function
                  VRPDeveloper Level 3

                  Put this thing at order level ...

                   

                  <mx:SummaryField dataField="PRICE"

                  operation="

                  MAX"

                  label="

                  Total"/>

                   

                  If this post answers your question or helps, please kindly mark it as such.

                  • 6. Re: AdvancedDataGrid Summary Row Max Function
                    VRPDeveloper Level 3

                    I have done complete code for u ... Run complete code of it and u will get what u want

                     

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
                        <mx:Script>
                            <![CDATA[
                                import mx.collections.ArrayCollection;
                                [Bindable]
                    private var dpFlat:ArrayCollection = new ArrayCollection([
                      {Region:"Southwest", Territory:"Arizona",
                          Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
                      {Region:"Southwest", Territory:"Arizona",
                          Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}, 
                      {Region:"Southwest", Territory:"Central California",
                          Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}, 
                      {Region:"Southwest", Territory:"Nevada",
                          Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}, 
                      {Region:"Southwest", Territory:"Northern California",
                          Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
                      {Region:"Southwest", Territory:"Northern California",
                          Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}, 
                      {Region:"Southwest", Territory:"Southern California",
                          Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
                      {Region:"Southwest", Territory:"Southern California",
                          Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
                    ]);

                     

                            ]]>
                        </mx:Script>
                       
                        <mx:AdvancedDataGrid id="myADG"
                            width="100%" height="100%"
                            initialize="gc.refresh();">       
                            <mx:dataProvider>
                                <mx:GroupingCollection id="gc" source="{dpFlat}">
                                    <mx:Grouping>
                                        <mx:GroupingField name="Region">
                                            <mx:summaries>
                                              <mx:SummaryRow summaryPlacement="group">
                                                <mx:fields>
                                                    <mx:SummaryField dataField="Actual"
                                                        label="Min Actual" operation="MIN"/>
                                                         <mx:SummaryField dataField="Estimate"
                                                                    operation="SUM"
                                                                    label="Total"/>
                                                    <mx:SummaryField dataField="Actual"
                                                        label="Max Actual" operation="MAX"/>
                                                </mx:fields>
                                              </mx:SummaryRow>
                                            </mx:summaries>
                                        </mx:GroupingField>
                                        <mx:GroupingField name="Territory">
                                            <mx:summaries>
                                              <mx:SummaryRow summaryPlacement="group">
                                                <mx:fields>
                                                    <mx:SummaryField dataField="Actual"
                                                        label="Min Actual" operation="MIN"/>
                                                         <mx:SummaryField dataField="Estimate"
                                                                    operation="SUM"
                                                                    label="Total"/>
                                                    <mx:SummaryField dataField="Actual"
                                                        label="Max Actual" operation="MAX"/>
                                                      
                                                </mx:fields>
                                              </mx:SummaryRow>
                                            </mx:summaries>
                                        </mx:GroupingField>
                                    </mx:Grouping>
                                </mx:GroupingCollection>
                            </mx:dataProvider>       
                           
                            <mx:columns>
                                <mx:AdvancedDataGridColumn dataField="Region"/>
                                <mx:AdvancedDataGridColumn dataField="Territory_Rep"
                                    headerText="Territory Rep"/>
                                <mx:AdvancedDataGridColumn dataField="Actual"/>
                                <mx:AdvancedDataGridColumn dataField="Estimate"/>
                                <mx:AdvancedDataGridColumn dataField="Min Actual"/>
                                <mx:AdvancedDataGridColumn dataField="Max Actual"/>
                                <mx:AdvancedDataGridColumn  dataField="Total"
                                    headerText="Total" textAlign="right" />
                            </mx:columns>
                       </mx:AdvancedDataGrid>

                     

                    </mx:Application>

                     

                    If this post answers your question or helps, please kindly mark it as such.

                    • 7. Re: AdvancedDataGrid Summary Row Max Function
                      mattp22 Level 1

                      I have run your code and it still doesn't answer my question.  If you go back

                      to the customer/order example.  I want to get the maximum order total for each customer, NOT the maximum line item in each order.

                      • 8. Re: AdvancedDataGrid Summary Row Max Function
                        VRPDeveloper Level 3

                        oh... My first feeling says you can do max on Total as Total is not datafield...you are creating Total field by applying operation SUM right ...then how you can use the value of it in other operation...

                         

                        The second feeling says , may be you can do by refreshing grouping collection in actionscript and then again creating summary field for max operation using actionscript at run time....but I am not sure about this approach....

                         

                        If this post answers your question or helps, please kindly mark it as such.