Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. calculate the weighted average

calculate the weighted average

Scheduled Pinned Locked Moved ASP.NET
tutorialhtmlcomhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    I sort of need to calculate the average of all the averages in a report. I have no clue how to do this, but I do have data. Do I have enough data here to do this, and perhaps some help with the formula I saw a couple of examples, but wow it looked so complex. http://study.com/academy/lesson/calculating-weighted-average-method-formula-example.html[^]

    If (sCIR.Length > 0) Then
    For idx As Integer = 0 To sCIR.Length - 1

                        rs\_DataRow = rs\_Table.NewRow()
                        rs\_DataRow(0) = sCIR(idx).FITEMNO
                        rs\_DataRow(1) = sCIR(idx).FDESCRIPT
                        rs\_DataRow(2) = sCIR(idx).FSHIPQTY
                        rs\_DataRow(3) = sCIR(idx).FCOST
                        rs\_DataRow(4) = sCIR(idx).FPRICE
                        rs\_DataRow(5) = sCIR(idx).FAMOUNT
                        rs\_DataRow(6) = sCIR(idx).FMARGIN\_PERCENT
                        rs\_DataRow(7) = sCIR(idx).FMARGIN\_PROFIT
    
                        'Add up the total cost value
                        m\_totalCost += sCIR(idx).FCOST \* sCIR(idx).FSHIPQTY
    
                        'Add up the total price value
                        m\_totalPrice += sCIR(idx).FPRICE \* sCIR(idx).FSHIPQTY
    
                        'Calculate the average margin of all the items
                        'm\_avgMarkup += 
    
                        'Add up the total margin value
                        m\_totalMargin += sCIR(idx).FMARGIN\_PROFIT
    
                        rs\_Table.Rows.Add(rs\_DataRow)
    
                    Next
    
                End If
    
    K D 2 Replies Last reply
    0
    • J jkirkerx

      I sort of need to calculate the average of all the averages in a report. I have no clue how to do this, but I do have data. Do I have enough data here to do this, and perhaps some help with the formula I saw a couple of examples, but wow it looked so complex. http://study.com/academy/lesson/calculating-weighted-average-method-formula-example.html[^]

      If (sCIR.Length > 0) Then
      For idx As Integer = 0 To sCIR.Length - 1

                          rs\_DataRow = rs\_Table.NewRow()
                          rs\_DataRow(0) = sCIR(idx).FITEMNO
                          rs\_DataRow(1) = sCIR(idx).FDESCRIPT
                          rs\_DataRow(2) = sCIR(idx).FSHIPQTY
                          rs\_DataRow(3) = sCIR(idx).FCOST
                          rs\_DataRow(4) = sCIR(idx).FPRICE
                          rs\_DataRow(5) = sCIR(idx).FAMOUNT
                          rs\_DataRow(6) = sCIR(idx).FMARGIN\_PERCENT
                          rs\_DataRow(7) = sCIR(idx).FMARGIN\_PROFIT
      
                          'Add up the total cost value
                          m\_totalCost += sCIR(idx).FCOST \* sCIR(idx).FSHIPQTY
      
                          'Add up the total price value
                          m\_totalPrice += sCIR(idx).FPRICE \* sCIR(idx).FSHIPQTY
      
                          'Calculate the average margin of all the items
                          'm\_avgMarkup += 
      
                          'Add up the total margin value
                          m\_totalMargin += sCIR(idx).FMARGIN\_PROFIT
      
                          rs\_Table.Rows.Add(rs\_DataRow)
      
                      Next
      
                  End If
      
      K Offline
      K Offline
      Kenneth Haugland
      wrote on last edited by
      #2

      It just sounds like you need the information about how many items are sold and at what price; then the math is pretty straight forward. (The sum of all (Item*Price))/Total numbers of items PS. You are not looking for the weighted sum, unless you don't know how many items are sold. But then your math can't be done.

      1 Reply Last reply
      0
      • J jkirkerx

        I sort of need to calculate the average of all the averages in a report. I have no clue how to do this, but I do have data. Do I have enough data here to do this, and perhaps some help with the formula I saw a couple of examples, but wow it looked so complex. http://study.com/academy/lesson/calculating-weighted-average-method-formula-example.html[^]

        If (sCIR.Length > 0) Then
        For idx As Integer = 0 To sCIR.Length - 1

                            rs\_DataRow = rs\_Table.NewRow()
                            rs\_DataRow(0) = sCIR(idx).FITEMNO
                            rs\_DataRow(1) = sCIR(idx).FDESCRIPT
                            rs\_DataRow(2) = sCIR(idx).FSHIPQTY
                            rs\_DataRow(3) = sCIR(idx).FCOST
                            rs\_DataRow(4) = sCIR(idx).FPRICE
                            rs\_DataRow(5) = sCIR(idx).FAMOUNT
                            rs\_DataRow(6) = sCIR(idx).FMARGIN\_PERCENT
                            rs\_DataRow(7) = sCIR(idx).FMARGIN\_PROFIT
        
                            'Add up the total cost value
                            m\_totalCost += sCIR(idx).FCOST \* sCIR(idx).FSHIPQTY
        
                            'Add up the total price value
                            m\_totalPrice += sCIR(idx).FPRICE \* sCIR(idx).FSHIPQTY
        
                            'Calculate the average margin of all the items
                            'm\_avgMarkup += 
        
                            'Add up the total margin value
                            m\_totalMargin += sCIR(idx).FMARGIN\_PROFIT
        
                            rs\_Table.Rows.Add(rs\_DataRow)
        
                        Next
        
                    End If
        
        D Offline
        D Offline
        deepankarbhatnagar
        wrote on last edited by
        #3

        Hi, you can get the average by doing this: m_avgMarkup += sCIR(idx).FMARGIN_PERCENT /idx below is the whole code,

        If (sCIR.Length > 0) Then
        For idx As Integer = 0 To sCIR.Length - 1

                            rs\_DataRow = rs\_Table.NewRow()
                            rs\_DataRow(0) = sCIR(idx).FITEMNO
                            rs\_DataRow(1) = sCIR(idx).FDESCRIPT
                            rs\_DataRow(2) = sCIR(idx).FSHIPQTY
                            rs\_DataRow(3) = sCIR(idx).FCOST
                            rs\_DataRow(4) = sCIR(idx).FPRICE
                            rs\_DataRow(5) = sCIR(idx).FAMOUNT
                            rs\_DataRow(6) = sCIR(idx).FMARGIN\_PERCENT
                            rs\_DataRow(7) = sCIR(idx).FMARGIN\_PROFIT
        
                            'Add up the total cost value
                            m\_totalCost += sCIR(idx).FCOST \* sCIR(idx).FSHIPQTY
        
                            'Add up the total price value
                            m\_totalPrice += sCIR(idx).FPRICE \* sCIR(idx).FSHIPQTY
        
                            'Calculate the average margin of all the items
                            'm\_avgMarkup +=  sCIR(idx).FMARGIN\_PERCENT /idx
        
                            'Add up the total margin value
                            m\_totalMargin += sCIR(idx).FMARGIN\_PROFIT
        
                            rs\_Table.Rows.Add(rs\_DataRow)
        
                        Next
        
                    End If
        

        hi

        J 1 Reply Last reply
        0
        • D deepankarbhatnagar

          Hi, you can get the average by doing this: m_avgMarkup += sCIR(idx).FMARGIN_PERCENT /idx below is the whole code,

          If (sCIR.Length > 0) Then
          For idx As Integer = 0 To sCIR.Length - 1

                              rs\_DataRow = rs\_Table.NewRow()
                              rs\_DataRow(0) = sCIR(idx).FITEMNO
                              rs\_DataRow(1) = sCIR(idx).FDESCRIPT
                              rs\_DataRow(2) = sCIR(idx).FSHIPQTY
                              rs\_DataRow(3) = sCIR(idx).FCOST
                              rs\_DataRow(4) = sCIR(idx).FPRICE
                              rs\_DataRow(5) = sCIR(idx).FAMOUNT
                              rs\_DataRow(6) = sCIR(idx).FMARGIN\_PERCENT
                              rs\_DataRow(7) = sCIR(idx).FMARGIN\_PROFIT
          
                              'Add up the total cost value
                              m\_totalCost += sCIR(idx).FCOST \* sCIR(idx).FSHIPQTY
          
                              'Add up the total price value
                              m\_totalPrice += sCIR(idx).FPRICE \* sCIR(idx).FSHIPQTY
          
                              'Calculate the average margin of all the items
                              'm\_avgMarkup +=  sCIR(idx).FMARGIN\_PERCENT /idx
          
                              'Add up the total margin value
                              m\_totalMargin += sCIR(idx).FMARGIN\_PROFIT
          
                              rs\_Table.Rows.Add(rs\_DataRow)
          
                          Next
          
                      End If
          

          hi

          J Offline
          J Offline
          jkirkerx
          wrote on last edited by
          #4

          That's a point in the right direction. I'll try something similar to that.

          If (sCIR.Length > 0) Then
          Dim idx As Integer = 0
          For idx = 0 To sCIR.Length - 1

                              rs\_DataRow = rs\_Table.NewRow()
                              rs\_DataRow(0) = sCIR(idx).FITEMNO
                              rs\_DataRow(1) = sCIR(idx).FDESCRIPT
                              rs\_DataRow(2) = sCIR(idx).FSHIPQTY
                              rs\_DataRow(3) = sCIR(idx).FCOST
                              rs\_DataRow(4) = sCIR(idx).FPRICE
                              rs\_DataRow(5) = sCIR(idx).FAMOUNT
                              rs\_DataRow(6) = sCIR(idx).FMARGIN\_PERCENT
                              rs\_DataRow(7) = sCIR(idx).FMARGIN\_PROFIT
          
                              'Add up the total cost value
                              m\_totalCost += sCIR(idx).FCOST \* sCIR(idx).FSHIPQTY
          
                              'Add up the total price value
                              m\_totalPrice += sCIR(idx).FPRICE \* sCIR(idx).FSHIPQTY
          
                              'Calculate the average margin of all the items
                              m\_avgMarkup += sCIR(idx).FMARGIN\_PERCENT
          
                              'Add up the total margin value
                              m\_totalMargin += sCIR(idx).FMARGIN\_PROFIT
          
                              rs\_Table.Rows.Add(rs\_DataRow)
          
                          Next
          
                          m\_avgMarkup = m\_avgMarkup / idx
          
                      End If
          
          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups