Finding difference at group level - reporting-services

I have 3 months of AR data. From SQL I am populating details records for 3 months. In SSRS I am grouping the totals by month and showing only group summary. I want to calculate the variance by difference between current month and previous month. Please see the attached output file.
Could anyone help me on finding the variance at group level. How do I calculate the difference by using previous function?
Is there any way to find individual group sum of the particular field like this one
Sum(Fields!Current.Value, "DataSet1")

Something like this perhaps?
=Sum(iif(month(Fields!myDate.Value) = month(Max(Fields!myDate.Value)), Fields!myVal.Value, 0))
-Sum(iif(month(Fields!myDate.Value) = month(dateadd("M", -1, max(Fields!myDate.Value))), Fields!myVal.Value, 0))
Where myDate is the date used to group the months on, and myVal is the specific data for the column
UPDATE
Using this dataset
EOM myValue
09/30/2015 2
10/31/2015 6
11/30/2015 19
Gives this basic report
You can then use this formula (based on the original one in the original answer above) to determine the difference between the last and the penultimate row
=Sum(
iif(month(CDate(Fields!EOM.Value)) = month(Max(Fields!EOM.Value)),
Fields!myValue.Value,
0)
)
-Sum(iif(month(CDate(Fields!EOM.Value)) = month(dateadd("M", -1, max(CDate(Fields!EOM.Value)))),
Fields!myValue.Value,
0)
)
Then place this in the footer of the tablix as shown
This shows the difference between the two rows
Is this the behaviour you require? If not please clarify further in the original question as an update/edit.

Related

SSRS how to stop repeating year on a bar chart

I was wondering if a dataset has a year and month for a whole year dataset. How can you have it so the year part isnt showing up for every month on the chart. so say if the report is ran for 01/04/2015 to 31/03/2016, the year part appears twice but not repeating 12 times for each month.
Just another quick question, in my chart I have formated the date i am using which the values looks like the following '2015-09-02 00:00:00.000' so in the chart category I have the date formated to show as (format(date,"MM/yy"))
this is used in the group by as i need the data for monthly.
However by doing this it takes ages for the chart to load, is there any better way to do this for monthly, the result set is about 90,000 rows
If you have a dataset query like
SELECT RIGHT(CAST(MONTH(soh.OrderDate) + 100 AS char(3)), 2) + '/' + RIGHT(CAST(YEAR(soh.OrderDate) AS char(4)), 2) AS MMYY, YEAR(soh.OrderDate) AS YYYY, MONTH(soh.OrderDate) AS MM, SUM(sd.OrderQty)
AS Qty
FROM Sales.SalesOrderHeader AS soh INNER JOIN
Sales.SalesOrderDetail AS sd ON sd.SalesOrderID = soh.SalesOrderID
WHERE (soh.OrderDate BETWEEN #StartDate AND #EndDate)
GROUP BY YEAR(soh.OrderDate), MONTH(soh.OrderDate)
For the first question set pick yyyy ,mm as category group
For the second question pick mmyy as category group then right click on category group properies, click sorting and add yyyy and mm in the change sorting options dialog.
SalesOrderDetils in Adventurworks2012 contains 121,000 records and the charts are returned preety quickly on my low spec pc.

SSRS Sum Values Based on Earliest Date

I'm trying to sum a net balance based on the earliest date in an SSRS report. In this case there are only 2 dates, but there can be more dates not more than 7 days.
Here's a sample of my data:
Here's what I'm trying to get with the earliest date of 10/26/15:
I've tried the following code, but not able to get this to work:
=Sum(IIf(DateDiff("d",Fields!SettleFullDate.Value,today())>=7
and DateDiff("d", Fields!SettleFullDate.Value, today())<7
and Fields!SETTLEBALANCE.Value>0), Fields!SETTLEBALANCE.Value, 0)
Update: I tried the code below and keep getting an error on the report. Could it be that I need to change the date field to an integer?
Thanks in advance for your help!
To compare the sum of values of two dates, the maximum and minimum in a set you can use the following equation
=Sum(iif(Fields!myDate.Value = Max(Fields!myDate.Value), Fields!myVal.Value, 0))
-Sum(iif(Fields!myDate.Value = MIN(Fields!myDate.Value), Fields!myVal.Value, 0))
This Sums all the values that match the maximum date in the dataset together, and sums all the values that match the minimum date in the dataset together, and takes one from the other.
It is irrespective of which dates you ask to be received, the above approach will work only against the records that you return to SSRS. So if you have a filter (WHERE clause) to return records between Date1 and Date2 this will still apply (Note - don't actually use 'Between' in the query)
Rather than using the maximum and minimum dates as listed here, you could also calculate a date similar to your original approach using
dateadd("d", -7, Fields!MySpecificDate.Value)
And insert that to the expression above.
Hopefully this is what you require - if not please let me know.

SSRS - Hide Results for future months

I'm producing a line graph within SSRS using SQL Queries. I have a line graph with 4 datasets (3 using lookup function).
My queries calculate values for each month of current year. As we are only in June, values of months from July to December are 0. I don't want that they were displayed on graph and on axis.
Can anyone point me in the right direction? I've tried to add a filter to the category group for the axis but this hasn't worked
Expression: Month_field
Operator: <
Value: =Month(Today())
my sql query is a build up of months for this year so I can get a result for all months ( I was having Issues returning 0 as a value for a month)
eg..
(SELECT * FROM (VALUES(DATENAME(month,'2015-01-01'),1)
,(DATENAME(month,'2015-02-01'),2)
,(DATENAME(month,'2015-03-01'),3)
,(DATENAME(month,'2015-04-01'),4)
,(DATENAME(month,'2015-05-01'),5)
,(DATENAME(month,'2015-06-01'),6)
,(DATENAME(month,'2015-07-01'),7)
,(DATENAME(month,'2015-08-01'),8)
,(DATENAME(month,'2015-09-01'),9)
,(DATENAME(month,'2015-10-01'),10)
,(DATENAME(month,'2015-11-01'),11)
,(DATENAME(month,'2015-12-01'),12)) AS Mnth(" Month ",MnthSort)) AS M
followed by the below to returnvalues greater than 1st fay of current year and less than 1st day of current month
WHERE Received1Date >=dateadd(mm,datediff(mm,0,getdate())-12,0)AND Received1Date < dateadd(mm,datediff(mm,0,getdate()),0)
My issue is when using my query in SSRS on a line graph all months display on Axis and all future results are 0 - I know this is expected because of my query but just wondering if there is something I can do to the graph within SSRS to exclude all future months?
Why don't you filter the data in your query?
select values
from table
where transaction_date >= Getdate()
this way those future months are not options to be displayed.

SSRS Charts data

I have situation where I need to create a column chart.
I have a field NotificationLog.Duedate . With this due date I need to create a chart with various condition.
I need to calculate the count of rows with conditions like below
NotificationLog.Duedate < Present date
NotificationLog.Duedate > Present date & NotificationLog.DueDate-Present date < 8 days
NotificationLog.Duedate > Present date & NotificationLog.DueDate-Present date > 8 days
Using the above counts I need to create a column Chart which with the three categories in X axis and Days marked in Y axis.
As of now I get the NotificatonLog.Duedate in a dataset with several other columns . How Can i proceed from this point and accomplish my requirement .
Thanks !
You need to set up an approriate expression-based field to group on.
I have a simplified Dataset to replicate your issue:
I have added a Calculated Field to the Dataset, called DuedateGroup:
The expression is:
=Switch(Fields!Duedate.Value < Today(), "Overdue"
, Fields!Duedate.Value > Today() and Fields!Duedate.Value < DateAdd(DateInterval.Day, 8, Today()), "Near Due"
, Fields!Duedate.Value > Today() and Fields!Duedate.Value > DateAdd(DateInterval.Day, 8, Today()), "Far Due")
i.e. the three groupings you require.
Now you can just use the new field in the Chart:
Looks OK to me.
If you didn't want to set up a Calculated Field, you could add the group expression directly into the Category Group at the Chart level, but I like the Calculated Field option.

Using the NOW Function In Access

I am setting up a code to pull all employees hired within the last 2 years who got a certain rating. I have been looking into the YEAR(NOW()) function but I am having a difficult time setting it up. I need to use the NOW function because I need it to pull the data from the time the user access the query. The ratings are completed every following feburary (i.e 2013 ratings will be completed in February of 2014) so it needs to read something like
YEAR(NOW()-12) but it
This way if I were to run it today it would go back and pull the ratings for 2012 and 2011 since 2013 have not yet been completed.
My whole code looks like:
SELECT dbo_v_TMS_QPR_01_Score.TMS_ID, dbo_v_TMS_QPR_01_Score.QPR_Year, dbo_v_TMS_QPR_01_Score.Final_QPR_Score
FROM O867IA_VJOBHST INNER JOIN dbo_v_TMS_QPR_01_Score ON O867IA_VJOBHST.SYS_EMP_ID_NR = dbo_v_TMS_QPR_01_Score.GEMSID
WHERE (((dbo_v_TMS_QPR_01_Score.Final_QPR_Score)>="1.25") AND ((O867IA_VJOBHST.EMP_ACN_TYP_CD)="HIR") AND ((O867IA_VJOBHST.REC_EFF_STT_DT)=Year(Now()-12)))
GROUP BY dbo_v_TMS_QPR_01_Score.TMS_ID, dbo_v_TMS_QPR_01_Score.QPR_Year, dbo_v_TMS_QPR_01_Score.Final_QPR_Score;
But I keep getting the error: INCONSISTENT DATATYPES: EXPECTED DATE GOT NUMBER (#932)
What you have does not work. It subtracts 12 days off the current date/time and then converts it to the year. Thus, it returns 2013.
Use the dataadd() function. The following is a blank query in the query designer.
I am asking for today's date minus 12 months. See output below.
I would THINK you want something like:
If Month(Now()) > 3 then 'If it's after Feb, we want the last 2 years
LastDayOfPrevYear = DateAdd("d", -1, DateSerial(Year(Now()), 1, 1))
Else 'If it's before March, we want the 2 years prior to last year
LastDayOfPrevYear = DateAdd("d", -1, DateSerial(Year(Now())-1, 1, 1))
End If
SELECT dbo_v_TMS_QPR_01_Score.TMS_ID, dbo_v_TMS_QPR_01_Score.QPR_Year, dbo_v_TMS_QPR_01_Score.Final_QPR_Score
FROM O867IA_VJOBHST INNER JOIN dbo_v_TMS_QPR_01_Score ON O867IA_VJOBHST.SYS_EMP_ID_NR = dbo_v_TMS_QPR_01_Score.GEMSID
WHERE (((dbo_v_TMS_QPR_01_Score.Final_QPR_Score)>="1.25") AND ((O867IA_VJOBHST.EMP_ACN_TYP_CD)="HIR") AND ((O867IA_VJOBHST.REC_EFF_STT_DT)>=DateAdd("m", -24, LastDayOfPrevYear)))
GROUP BY dbo_v_TMS_QPR_01_Score.TMS_ID, dbo_v_TMS_QPR_01_Score.QPR_Year, dbo_v_TMS_QPR_01_Score.Final_QPR_Score;
This will give you a "rolling" 24 month timespan from the last date of the previous year.
This may need a little tweaking, but it should be, at the very least, extremely close.