Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

YTD/PTD Groupings

Posted on 2009-05-08
2
Medium Priority
?
536 Views
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

0
Comment
Question by:DEN_Jimbo
[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 Comments
 
LVL 9

Accepted Solution

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

Project, Item Date, Hours  

You can do

SELECT
 Project, YEAR(Item Date), SUM(Hours)
FROM
 <Source>
GROUP BY Project, Year(Item Date)

Example


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

0
 

Author Comment

by:DEN_Jimbo
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">
<fields>Title,State,Site,Rstlabel,ProjectType,Start,ActualStart,BaselineFinish,BaselineWork,BaselineCost,Finish,Cost,Work,ExecSponsor,Owner,PM</fields>
<query>
<Where>
<Eq>
<FieldRef Name="State" /><Value Type="Text">Active</Value>
</Eq>
</Where>
</query>
</multiList>
<sqlOp op="distinct">
<sortOrder>ASC</sortOrder>
<dstTableName>SIP Projects</dstTableName>
<tableName>Projects</tableName>
<fieldName>Title,State,Site,Rstlabel,ProjectType,Start,ActualStart,BaselineFinish,BaselineWork,BaselineCost,Finish,Cost,Work,ExecSponsor,Owner,PM</fieldName>
</sqlOp>
<resultSet>Projects</resultSet>
</root>

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

After much searching across the internet I have found that you could not set the name of the file you were attaching to dynamic report subscriptons in Microsoft Reporting Services. I did manage to find one article showing you how your could make a s…
Introduction Earlier I wrote an article about the new lookup functions (http://www.experts-exchange.com/A_3433.html) that ship with SQL Server 2008 R2.  In this article I’m going to show you another new feature of SSRS 2008 R2, this time in the vis…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

688 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