Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to show results from 2 timeframes?


How to show results from 2 timeframes?

Author
Message
pluto1415
pluto1415
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 4
We would like to generate a report that shows the following:

SalesPersonA - Sales for Jan-June2012 - Sales for Jan-June2013
SalesPersonB - Sales for Jan-June2012 - Sales for Jan-June2013
SalesPersonC - Sales for Jan-June2012 - Sales for Jan-June2013

I can write 2 datasets that find "Sales for Jan-June2012" and "Sales for Jan-June2013" - but I can't figure out how to display the results in one table, sorted by Sales Person...

Then we will want to calculate the diff between 2012 & 2013, but I think I can write the expression for that.
geoff5
geoff5
SSC-Enthusiastic
SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)

Group: General Forum Members
Points: 180 Visits: 543
My preferred approach would be to do the pivoting of the data in the query for the dataset, like this:

select
sales_person_id,
JanJun2012 = sum(case when month(sale_date) <= 6 and year(sale_date) = 2012 then sale_amount else 0 end),
JanJun2013 = sum(case when month(sale_date) <= 6 and year(sale_date) = 2013 then sale_amount else 0 end)
from
sales_data
group by
sales_person_id



But this can also be done in SSRS by putting the following expressions in a scope that represents each sales person:

=Sum(IIf(Month(Fields!sale_date.Value) <= 6 And Year(Fields!sale_date.Value) = 2012, Fields!sale_amount.Value, 0))
=Sum(IIf(Month(Fields!sale_date.Value) <= 6 And Year(Fields!sale_date.Value) = 2013, Fields!sale_amount.Value, 0))


Steven Willis
Steven Willis
SSC-Addicted
SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)

Group: General Forum Members
Points: 477 Visits: 1721
pluto1415 (7/26/2013)
We would like to generate a report that shows the following:

SalesPersonA - Sales for Jan-June2012 - Sales for Jan-June2013
SalesPersonB - Sales for Jan-June2012 - Sales for Jan-June2013
SalesPersonC - Sales for Jan-June2012 - Sales for Jan-June2013

I can write 2 datasets that find "Sales for Jan-June2012" and "Sales for Jan-June2013" - but I can't figure out how to display the results in one table, sorted by Sales Person...

Then we will want to calculate the diff between 2012 & 2013, but I think I can write the expression for that.



SELECT
result.SalesPersonID,
result.SalesPerson,
result.[2013 Sales] - result.[2012 Sales] AS [Difference]
FROM
(
SELECT
Y12.SalesPersonID,
Y12.SalesPerson,
SUM(Y12.Sales) OVER (PARTITION BY Y12.SalesPersonID) AS [2012 Sales],
SUM(Y13.Sales) OVER (PARTITION BY Y13.SalesPersonID) AS [2013 Sales],
FROM
[Sales for Jan-June2012] AS Y12
INNER JOIN
[Sales for Jan-June2013] AS Y13
ON Y12.SalesPersonID = Y13.SalesPersonID
) result
ORDER BY
result.SalesPerson



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search