YTD/PTD Groupings

Posted on 2009-05-08
Last Modified: 2012-05-06
Hi- I need to run a report that would summarize Project to date and Year to date items.  These currently are all retrieved in 1 data set.

How do I display them to they are group together eg.

Project name, Period, Start date, hours
Project1          PTD   Max(date)eg 2/2/2009    100
project1          YTD   1/1/2009       40

Question by:DEN_Jimbo

Accepted Solution

Hwkranger earned 500 total points
ID: 24337443
If your line data looks something like:

Project, Item Date, Hours  

You can do

 Project, YEAR(Item Date), SUM(Hours)
GROUP BY Project, Year(Item Date)


DECLARE @Table TABLE (Project nvarchar(10), ItemDate datetime, Hours float)

INSERT INTO @Table VALUES ('Project 1', '01/01/05', '5.5')

INSERT INTO @Table VALUES ('Project 1', '02/01/05', '1.5')

INSERT INTO @Table VALUES ('Project 1', '03/01/05', '2.5')

INSERT INTO @Table VALUES ('Project 1', '04/01/05', '3.5')

INSERT INTO @Table VALUES ('Project 1', '01/01/06', '4.5')

INSERT INTO @Table VALUES ('Project 1', '02/01/07', '6.5')

INSERT INTO @Table VALUES ('Project 2', '01/01/05', '5.5')

INSERT INTO @Table VALUES ('Project 2', '02/01/05', '1.5')

INSERT INTO @Table VALUES ('Project 2', '03/01/05', '2.5')

INSERT INTO @Table VALUES ('Project 2', '04/01/05', '3.5')

INSERT INTO @Table VALUES ('Project 2', '01/01/06', '4.5')

INSERT INTO @Table VALUES ('Project 2', '02/01/07', '6.5')

SELECT Project, SUM(Hours), Year(ItemDate)

FROM @Table

GROUP BY Project, Year(ItemDate)

Open in new window


Author Comment

ID: 24340288
hum.  I am tring to do this with reporting serices not plain sql.  I think its the way I do the layouts.  For example my dataset is included below.  Can I combine a table with two datasets that are grouped on the projectname or Title? because then I could do a full query for PTD(eg the code below) then do a query from the start of the year to present.

<multiList title="Projects" relativeSiteUrl="@URL!" tableName="Projects" type="List">





<FieldRef Name="State" /><Value Type="Text">Active</Value>





<sqlOp op="distinct">


<dstTableName>SIP Projects</dstTableName>






Open in new window


Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction As you'll probably know, a data region in a SQL Server Reporting Services report can be linked to only one dataset.  This makes it troublesome when you need to display data from more than one dataset in the same data region.  SQL Serve…
This code started out as a fix for a customer that had incoming data that was hunderds of numbers and words long that was to fit in one column. The problem was that the customer did not want to split words or numbers when wrapping in the column. …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now