Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SSRS - Calculate $ cost on monthly basis Expand / Collapse
Author
Message
Posted Friday, December 28, 2012 10:55 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, January 21, 2013 1:42 PM
Points: 8, Visits: 20
I am new to SSRS and stuck at a point and can not move further and so need your help

I have a question regarding calculating sum of sales for different months.

I have a report which shows weekly sales $ for east and west cost office. I have a report which shows weekly sales $ for east and west cost office. The datasource is a table which contains weekly sales data for the offices like:

Week $ Sales_Item1 $ Sales_Item2 $ Sales_Item3
Aug 20 1000 xyz abc
Aug 27 500
Sept 03 2000
etc
etc
etc


Report needs to show info like:

Week $ Sales_Item1 $ Sales_Item2 $ Sales_Item3
Aug 20 1000 xyz abc
Aug 27 500
Sept 03 2000
etc
etc
etc

Sum $ for Aug X Y
Sum $ for Sept A B




How do i calculate the sales for these individual items monthwise and show it on the report. What needs to be written in the "Expression" so as to get the sum of all 4 weeks data of the month?

Please reply.

Thanks
Post #1400982
Posted Monday, December 31, 2012 9:16 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, September 19, 2014 11:17 AM
Points: 1,184, Visits: 1,220
Rather than trying to do this in an expression, change your datasource and do it in T-SQL. Much easier.

Rob
Post #1401544
Posted Tuesday, January 1, 2013 10:05 PM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 1:53 AM
Points: 467, Visits: 867
If you are able to edit the SQL then do as robert says. If you aren't good with SQL or are unable to edit the SQL for some reason then here's an idea:

If the week field is a text datatype (not a true date) then you could create a calculated column as
=Left(Fields!Week.Value,4)   

This assumes that your weeks are as you've shown in your example, as either 3 or 4 letters followed by the day of the month.

You will also want to include the year in the group, that's important if your report spans multiple years.

If the week field is a proper date datatype then you can use this formula:

=MonthName(Month(Fields!Week.Value),False)

If you add a parent group to the details row, use that calculated column as the group.
You can then add totals for the groups. If you right click on the $Sales_Item1 details cell it will give you the option to "add total".

The results will look somewhat like this

Month  Week   $Sales_Item1 
Aug Aug 20 1000
Aug 27 500
Total 1500
Sept Sept 03 2000
Sep 10 100
Sep 17 0
Sep 24 0
Total 2100


If you really want it as per your example with the totals per month separate, then you can add a second tablix below and just use the grouping in it, i.e. change the details group to be grouped by month (see formulas above) and use something like
=sum(Field!@Sales_item1.value) 

for each cell expression.
Post #1401650
Posted Wednesday, January 2, 2013 9:01 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, January 21, 2013 1:42 PM
Points: 8, Visits: 20
Thanks for the reply Robert.

So, do I alter the source table, add new column(s) which can hold the values for the sum of the month(s)?
Post #1401891
Posted Thursday, January 3, 2013 6:42 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, September 19, 2014 11:17 AM
Points: 1,184, Visits: 1,220
engg.pankaj (1/2/2013)
Thanks for the reply Robert.

So, do I alter the source table, add new column(s) which can hold the values for the sum of the month(s)?

No, you wouldn't need to alter the table, but rather just write a query. Just sum up the values grouping by the month. You would use the SUM() aggregate function and the GROUP BY clause. Take a look at: http://www.sql-tutorial.net/SQL-GROUP-BY.asp
for an intro on how group by works.

Rob
Post #1402339
Posted Thursday, January 3, 2013 7:19 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, January 21, 2013 1:42 PM
Points: 8, Visits: 20
Hi Robert,

Thanks for the reply again.

I know how to write SUM() and group by queries in T-SQL however, I want to know how to write this query and show the result in that particular column.

If i right click on a column on the report, where do I write the query in it so that we can display the result of the query in that column.

I am new to SSRS and need guidance.

Thanks
Post #1402362
Posted Thursday, January 3, 2013 8:00 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, September 19, 2014 11:17 AM
Points: 1,184, Visits: 1,220
engg.pankaj (1/3/2013)
Thanks for the reply again.

I know how to write SUM() and group by queries in T-SQL however, I want to know how to write this query and show the result in that particular column.

If i right click on a column on the report, where do I write the query in it so that we can display the result of the query in that column.

I am new to SSRS and need guidance.

You put your query in the Dataset area of the report. First, make sure you have a data source that points to your database. Then create a new dataset (right click on Datasets and choose Add Dataset if you're creating your report in Report Builder -- it's similar in VS as well). From here you can either go to the query designer, or just past in your query into the text window.

Now in your tablix, make sure it's connected to that dataset (in the tablix properties, Dataset name). And then you can select the fields from your dataset for the columns of your report table.

HTH,
Rob
Post #1402399
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse