6 Replies Latest reply: Sep 20, 2017 3:55 AM by Anil Babu RSS

    Load 1 instance of a Field and Sum corresponding multiple values

    Fabrizio Giorgio

      Hi all,

       

      I have a table with  multiple Sales Order Lines for various sales orders.

       

      so my table looks like this:

       

      SOrder |    SO Line #     | SOrderLine Value

      A          |             1          |         10

      A          |             2          |         10

      A          |             3          |         15

      A          |             4          |         10

      B          |             1          |          5

      B          |             2          |         20

      B          |             3          |         10

       

      What I want to end up with is:

       

      SOrder     SO Total

      A          |          45

      B          |          35

       

      I can do a SUM(SOLineValue) as SOTotal Resident TableX Group By SOrderNo

       

      but how can I Load only 1 instance of the SOrder in my Totals Table?

       

      not sure if this makes sense...

       

      Reason for this, is that when i load from an SOrderline table, I get the Sorder repeated as many times as there are SOrder Lines, and this appears to be messing up some calculations that are made per SOrder, not SOrderline...

       

      please let me know your thoughts...

       

      thanks...

       

      F.Giorgio

        • Re: Load 1 instance of a Field and Sum corresponding multiple values
          Anil Babu

          May be this?

           

          Directory:

          LOAD * Inline [

          SOrder ,    SO Line #     , SOrderLine Value

          A          ,             1          ,         10

          A          ,             2          ,         10

          A          ,             3          ,         15

          A          ,             4          ,         10

          B          ,             1          ,          5

          B          ,             2          ,         20

          B          ,             3          ,         10

          ];

           

          LOAD SOrder, Sum([SOrderLine Value]) as [SO Total] Resident Directory Group By SOrder;

          DROP Table Directory;

            • Re: Load 1 instance of a Field and Sum corresponding multiple values
              Fabrizio Giorgio

              Thanks Anil,

               

              However, that would give me:

               

              SOrder     So Total

              A          |             45        |        

              A          |             45        |        

              A          |             45        |        

              A          |             45        |        

              B          |             35        |         

              B          |             35        |      

              B          |             35        |     

               

              Which I am trying to avoid...

               

              I need to simplify to:

               

              SOrder     SO Total

              A          |          45

              B          |          35

            • Re: Load 1 instance of a Field and Sum corresponding multiple values
              Antonio Mancini

              Hi Fabrizio,

              try like this

               

              LOAD SOrder,Sum(SOrderLineValue) as TotalValue Inline [
              SOrder | SO Line # | SOrderLineValue
              A | 1 | 10
              A | 2 | 10
              A | 3 | 15
              A | 4 | 10
              B | 1 | 5
              B | 2 | 20
              B | 3 | 10
              ]
              (delimiter is '|')
              Group By SOrder
              ;

              Regards,

              Antonio

                • Re: Load 1 instance of a Field and Sum corresponding multiple values
                  Fabrizio Giorgio

                  Sorry guys,

                   

                  i've just realised that adding the deposit field (per Sorder) to this table is causing the below:

                   

                  SOrder     So Total

                  A          |             45        |       

                  A          |             45        |       

                  A          |             45        |       

                  A          |             45        |       

                  B          |             35        |        

                  B          |             35        |     

                  B          |             35        |  

                   

                  I need to look further into the deposit field and see how I'm going to import it into the table without creating multiple lines (as the original source table has SOrderlines on it, if I import from there it will repeat by the number of SOrder lines...)... the SOTotals part below is working fine...

                   

                  SOCSOBalances:

                  LOAD

                  SOCSOrderNo,

                  Sum(SOCSOLineTotalincDisc) as SOCSOGrandTotal Resident SOCMaster Group By SOCSOrderNo;

                   

                  I will leave this open for a couple of days and will come back to it if I have more questions...

                   

                  thanks for your input though...

                   

                  cheers Fab