I have a report that I built in SSRS that calculates a sum of numbers for every business day going back 10 business days. There is a column group for each business day, and there are row groups for each item being totaled. The function to calculate the sum is a simple:
=Sum(Fields!INCOME.Value)
This returns data for example as such:
Now I am creating a report to indicate the change in data from day-to-day. I figured this would be simple with the Previous() function in SSRS. So I took the same dataset and in a new tablix I replaced the original calculation with:
=Sum(Fields!INCOME.Value)-Previous(Sum(Fields!INCOME.Value),"ASOFDT2")
The Column group is called ASOFDT2. This seems to work for all but the very first column, I get the following as a result:
My question is, does anyone know why this calculation is not performing in the first group, but is for all the rest? How can I make it properly calculate the first iteration of this? For informational purposes, I'm using SQL Server 2014, and I am building the report in Visual Studio 2013.
I have also reviewed the SO question: Use of Previous() function in reverse date sorted data in SSRS? though I am not sure how to apply this to my problem. The first column is my most recent set of data and I cannot select one column newer and just hide it.
The Previous() function gets the data in the Previous column. It doesn't have any understanding of what that data is, so if your columns are in Descending order, the Previous column will be the Next day, not the Previous day
It shouldn't be too hard to include the differential data in your dataset instead of trying to calculate it in the report. Just join the table to itself on YourDateColumn = DATEADD(dd, -1, YourDateColumn), and the right side of the join will have the previous day's data, and you can subtract for the difference.
Related
I have an SSRS report that contains a group where the row DataSet contains a date-time column in addition to other value columns. I want to place a pie chart at the top of my report that indicates totals from the newest row based on the date-time column within each group. How can I do this?
Here is a simple snippet of what the report looks like. The pie chart would basically total up all of the Outcomes for the newest "Started DT" row for each "Test Case" group. So, in the example report below, the chart would have a total of 1 "Passed" and 2 "Failed" on the pie chart.
I'm really having a hard time figuring out how to do this. I've tried adding a variable to the group that contains the Outcome from the first row, thinking that I could reference the total of the variables in my chart. Problem is..., SSRS won't let me put an aggregate expression on a Group variable.
I came up with a workaround. I added another dataset to my report that calls the same stored procedure, but with different parameters that restrict the number of days being reported to the newest date-time. This solution only worked for my particular situation because the stored procedure had a param that would allow me to get the data that I want.
I've never done this for a matrix and it's going a little over my head. Trying to make a sales report, and I can do the matrix just fine. The part I'm having trouble with and I haven't been able to find a direct answer for through googling is how to get a specific value out of the matrix.
Here is a picture of it:
Report
What I need is on the far right where it says total at the top. There I need to do another break out (dynamically would be preferred but not required) the first Column would be %change of 2013 -> 2014. Then of course then next would be 2014 to 2015 and so on.
Here is the design view if it helps: Design View
So the sum total of the year compared to the year previous.
I was trying to use iif and max but I think i'm just confusing myself but the expression i have in there is:
=Sum(iif(Max(Fields!Year.Value)=Fields!Year.Value,Fields!glamt.Value,1))
Just from my testing I got no idea what values it's pulling for that.
Something I've used before is to create a variable of the SUM of previous period, in you case year. So =SUM(IIF(Fields!Year.Value = "2017",Fields!glamt.Value,0) added into the Variables section of the report.
Then in a new column within the year grouping, you add your comparison formula;
=(SUM(glamt)-Variables!sum2017.Value) / Variables!sum2017.Value * 100.00
This gives you the percentage upshift/downshift, but you get the idea if you want the actual figure of increase/decrease in sales etc.
One of the downsides of this approach is that the variables will need to be added manually and you may have a large number depending on the number of previous periods you want to compare but should suffice for say the last 5 years.
I am working on an SSRS report that gets its data from an OLAP cube. In the OLAP cube I have a field named WeekOfYear which gives me the week number of the year based on the date. For example, week 1 for January 1st (if January 1st falls on a Monday) and week 2 for January 8th. My data is grouped by this field but now I want to be able to compare the data from this week of the year to the previous year's week of the year. Like comparing Week 1 of 2015 to Week 1 of 2014. Is there anyway that I can accomplish this? I appreciate any help. Thanks.
There is a LookUp function that should be able to do what you need.
You mention you have a WeekOfYear field. This also assumes you have a Year field (or can calculate it with **YEAR(Fields!YouDateField.Value) )
=LookUp(Fields!YourYearField.Value - 1 & "|" & Fields!WeekOfYear.Value, Fields!YourYearField.Value & "|" & Fields!WeekOfYear.Value, Fields!YourValueField.Value, "YourDataSet")
If you are actually summing multiple rows of data from your cube, you would need to use LookUpSet to get all the values and sum them with a custom function (since Microsoft couldn't possibly envision users wanting to SUM multiple records). Luckily users have already created a function - SumLookup. See How to combine aggregates within a group with aggregates across groups within SSRS if needed.
If you have access to the OLAP cube and can edit this, you could define a new Calculated Measure on the cube. How exactly this would work depends on the set up of your date hierarchies. You can also access this and define calculated measures through the Query Designer while constructing your dataset in Report Builder/Visual Studio.
Right-click in the cube browser and choose "New Calculated Member".
Reporting on weeks across years can be difficult due to the fact that the number 7 doesn't fit neatly into 365 or 366, so you always end up with a little over 52 weeks. Since the 1st of January could be a Sunday one year, and a Tuesday on the next (2012/2013), it's not always a good idea to directly compare these. So people may work around this by defining the 7-day weeks for the year against their date dimension. One year you may have 52 weeks, another you'd have 53. This is a little off topic, so I'll link to an explanation of this here, but it is important to be aware of this in order to implement my suggestion below.
Assuming you have a nice hierarchy on your date dimension that can aggregate up Weeks to Year level, you can create a new measure in your cube using the ParallelPeriod function.
[Measures].[SalesSPLY] AS
(
ParallelPeriod
(
[Dim Date].[ReportingCalendar].[ReportingYear],
1,
[Dim Date].[ReportingCalendar].CurrentMember
),
[Measures].[Sales]
)
My example MDX assumes that you already have a hierarchy called ReportingCalendar created on your date dimension. Yours may be named differently.
Now if you browse your cube and select WeekOfYear, Sales, and SalesSPLY, you will see your value for this year's week 1, alongside last year's.
OLAP cubes are very good at this type of time-based intelligence, as they can very quickly provide aggregated and offset data in a way that would be slower to run in an RDBMS or within SSRS itself.
I have an SSRS report that is currently pulling a single dataset. This dataset contains records of inventory we have. Each record is a separate asset.
I want my report to group by a certain field, and then subgroup by certain criteria that are determined with a couple different fields. Basically there is one parent group, and three adjacent subgroups. My grouping functionality is working correctly, however I am finding it difficult to add totals to each of the adjacent subgroups. When I add a total, it is totaling the specific field within the scope of the entire dataset, instead of limiting the total to just that subgroup.
How can I add totals per field within subgroup?
EDIT: Added sample data and explanation:
You can ignore the function code field, that is what I am using to group on the parent group.
asset number,description,first year,acquisition cost,function code
190,random asset,2008,5000,100
193,random asset45,2008,56000,100
197,random asset26,2014,3000,100
191,random asset27,2014,7000,100
192,random asset36,2013,15000,100
I can't seem to attach screenshots, so here goes..
In the report you can see three subgroups; Assets, AssetAdditions, AssetDeletions. In the tablix, you can see where these groups are positioned. You can also see a row directly beneath the group that is supposed to total the subgroup at the end. However, for some reason the scope is only taking into account the entire dataset. I have tried to modify the expression in the Sum function [Sum(acq_cost), "Assets"], adding in the scope parameter but then it does not allow me to even run the report. It yells at me saying that "Assets" is an invalid scope.
The easiest way I have done this in 2012 VS is to have it return as part of the data set and have it sum up the value.
For instance if you have a quantity for inventory, and you have a subset where you only want the total quantity for that set, you add another column to your dataset called TotalSetQuantity and the subtotal field will have the expression =SUM(Fields!TotalSetQuantity.Value) rather than =SUM(Fields!Quantity.Value).
You can try iif statements within your report like =sum(iif(Fields!ColA.Value=1,Fields!Quantity.Value,0) but I had some troubles getting that to work.
Hope that helps, I ran into this issue this past week and the first option worked like a charm for me.
I have an rdlc report file, and I am trying to make a sum which can only include the last item in each group. I have a table kind of like this:
Place = ? (Group header 1)
User = ? (Group header 2)
Date =Last(Fields!Number.Value) (Group header 3)
Number =Fields!Number.Value (Detail row)
So, in other words, in User there, I want a sum of Date... if that made sense...
The Numberrows contain many numbers per Date. But Date shows only the last number for that day, because the rest doesn't count (but must be displayed) In User I want to sum up those last numbers for all the dates for that user. And same with Place (which would be the sum of every last number for every day for every user).
Could anyone help me with this? I tried the obvious (to me at least) =Sum(Last(Fields!Number.Value)), but (also tried to specify the group in those functions, but didn't make a difference because) I get an error when I try to compile which says:
The Value expression for the textbox 'numberTextbox' contains an aggregate function (or RunningValue or RowNumber functions) in the argument to another aggregate function (or RunningValue). Aggregate functions cannot be nested inside other aggregate functions.
Which I guess kind of makes sense... but how do I do this then?
Update: I have solved the issue by adding another column, and copying those last numbers into that column. This way I can display all the numbers, and do the summing on the column that only contains the ones that is going to be in the sum. I am still very curious to if anyone have a solution to my original problem though... so please post an answer if you do!
Not sure I understand exactly what you're trying to do. Maybe something like =Last(Fields!Number.Value,"Group 1") + Last(Fields!Number.Value,"Group 2") + Last(Fields!Number.Value,"Group 3"), instead using a sum function?
the easiest way to do this would be to modify your dataset to only include the records your are displaying in the date field, that way you could just use a simple sum() instead of trying to do something weird and screwy and might not work.
Modifying the data set may really be the simplest solution, but if you really wanted to do this without complicating the query you could try "custom aggregation".
The exact techniques for this depend on the version of SSRS, and my understanding is it didn't really work that well before SSRS 2008.
The idea is, you write some custom code to maintain an array containing the last value for each date. One function updates the "last value" for a date, and another sums the values in the array. Your header calls the latter function; you conspire to cause the former function to be called once for each detail row before the header is processed.
Here's a blog with a write-up that explains the technique in SSRS 2008.
It also gives some insight into how you can try to make this work in SRSS 2005, but again apparently that's not as reliable.