Solved

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

Posted on 2011-03-01
2
226 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

690 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