Solved

How do I sum data by month/YYYY in VB code in VS2010?

Posted on 2011-03-01
2
224 Views
Last Modified: 2012-05-11
Hello:

I would like to sum the total of several columns by each month based upon a user selected date range.  

This is what I have so far:

HERE I GRAB ALL THE DATES AVAILABLE IN THE DATE RANGE
----------------------------------------------------------------------------------
Dim dateList = From id In wellData.tblBWgallons _
                         Where id.InputDate >= CDate(pckrStartDate.Text) _
                         AndAlso id.InputDate <= CDate(pckrEndDate.Text) _
                         AndAlso id.Cumulative > 0 _
                         Order By id.InputDate Ascending _
                         Select id.InputDate

HERE I MAKE A LIST  BY M/YYYY
--------------------------------------------------------------
        Dim MonthList As New List(Of String)

        For Each m As Date In dateList
            Dim mon As String = CStr(m.Month)
            Dim YY As String = CStr(m.Year)
            Dim DateName As String = mon & "/" & YY

            If Not MonthList.Contains(DateName) Then
                MonthList.Add(DateName)
            Else
                'do nothing
            End If
        Next

PROBLEM AREA - I CAN'T FIGURE OUT HOW TO GRAB THE DATA BY THE LIST
-------------------------------------------------------------------------------------------------

        For Each rec In MonthList
            Dim mmyy As String = rec  (EXAMPLE mmyy would be 3/2010)

            Dim getRecords = Aggregate id In wellData.tblBWgallons _
                             Where CDate(id.InputDate.Value.ToString("m/yyyy")) = mmyy _
                             Into Sum(id.Cumulative)

        Next

Any help would be most appreciated!  
0
Comment
Question by:Karen Wilson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 

Accepted Solution

by:
Karen Wilson earned 0 total points
ID: 35008924
I got it...  Had to flip each record in the MonthList back to a date.

For Each rec In MonthList

            Dim mmyy As Date = rec
            Dim m As String = mmyy.Month
            Dim y As String = mmyy.Year


            Dim getRecords = Aggregate id In wellData.tblBWgallons _
                             Where CDate(id.InputDate.Value).Month = m _
                             And CDate(id.InputDate.Value).Year = y _
                             Into Sum(id.Cumulative)

        Next

0
 

Author Closing Comment

by:Karen Wilson
ID: 35008935
I figured it out myself....  after reading my own question!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FInd Image Control Gridview 3 38
MYSQL responding very slow 3 51
ASP.NET Calendar Control 5 29
Asp.Net Session Question 2 36
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question