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.
Related
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 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.
I am trying to create a query on a table that filters out dates. I need to display all records previous to a specific date, but need this to be dynamically updated annually.
Specifically, I need to find dates prior to October 1 of the previous year. (i.e. anything prior to Oct 1, 2012.)
I know I can use '<#10/1/2012#' but would like to make this dynamic to update every year, as this same function will be utilized for multiple queries.
I have tried several iterations of the Date() function to get this to work, to no avail.
Things that don't work are...
Year([TrainingDate])
[TrainingDate] < DateSerial(Year(Date())-1,10,1)
Date() is the current date, so Year(Date()) is the current year.
I am looking for optimized solution for the below problem -
I have a cube which contains Date dimension which has one hierarchy month->quarter->year.
I have created a cube, all good. Now my ssrs report requires all my dimension customer sales attributes along with the calculations like
last month profit,
current month profit,
last 6 months profit (listing every month),
last month transactions,
last year profit vs current year profit.
As i have created a hierarchy all my calucations for every month and every year and every quarter already pre-calculated in the CUBE. Now to retrieve the above listed calculations, what is the best way to do these time calculations? Where to put these calculations in CUBE or in the SSRS DATASET?
Could you please suggest some good approach and how to do it?
Although it's certainly possible - if you're comfortable with MDX - to write your query to get all these calculations into your dataset, it's usually better for reusablity across many reports to put these types of calculations in the cube. That way, other tools can also use the time calculations if you decide to use Excel or a 3rd party application.
You can use the Business Intelligence Wizard from the Calculations tab to do this - here's an article for SSAS 2005 that's still applicable to later versions: http://www.obs3.com/pdf/A%20Different%20Approach%20to%20Time%20Calculations%20in%20SSAS.pdf
And here's another approach to do something similar:
http://www.bidn.com/articles/mdx-and-dmx/169/mdx-time-calculations-done-the-right-way
UPDATE:
For named sets to handle date ranges like the last 6 months from now, see this article: http://my.opera.com/duncans/blog/using-custom-sets-in-analysis-services-to-deliver-special-date-ranges-to-end-use
not sure if I get you, but the problem is that you need to get dynamic values and you have everything hard-coded?
You can get the previous member in a hierarchy with the prevmemebr function:
([Date].[Calendar].PrevMember, <your measure here>)
where date is the dimension and calendar is the hierarchy.
So if you are browsing by month, it will get the last months data for example
You have to calculate last month profit, current month profit, last 6 months profit as measures in the cube 'calculations' using mdx query. I recently did this for my 'revenue comparison report' where I calculatedlast month's revenue, last2monthsrevenue and priorquarterrevenue and used them. It worked!
I am using an MS Access db to track some tasks during the year. Each task has a due Month. I do not want to use exact dates as the convention in my team is to refer to the month. I don't want to store the dates in a date format as team members will be entering the due month by hand.
Is it possible to sort my fields in date order if the date is stored as a text string month? (eg. January, February rather than 31/01/2009, 28/02/2009).
If so, what would such a query look like?
Thanks in advance.
If you are storing only the month name, your will first need to convert to a date to get a month number, use a lookup table (MonthNo, MonthName) or use the Switch function. Here is an example of converting to a date:
SELECT Month(CDate(Year(Date()) & "/" & [MonthNameField] & "/1")) AS MonthNo
FROM Table
However, there is probably a good argument for storing a date based on the month name entered, this would prevent any confusion about years.
This should work
SELECT *
FROM TableName
OrderBy Month(date_field)
I would store the month as an integer 1-12 then you can easily sort them.
I would make a date field.
I would store 1/1/2009 for January 2009, 2/1/2009 for February 2009, and so forth. For display purposes, I'd format it so that it displayed only the month (or Month + Year -- can't imagine how you wouldn't want the year).
This makes it possible to take advantage of date operations on the field without messy conversions of text to date formats.
Thank you all for your responses. Sorry for the delay in responding - I'm working on this issue again now.
For clarity, the DB is to be used to track a schedule of events within a 12 month period. The year does not need to be stored as everything in the DB is referring to the same year. A new copy of the DB will be made at the beginning of 2010.
I'm really keen to actually store the month as a word rather than any kind of value or date field as when bulk adding tasks I will likely edit the table directly rather than use a form.
I realise this is dead but google brought me here while i was looking so thought I would add to it:
I had this problem myself (Access 2010) and found a decent answer here: http://www.vbforums.com/showthread.php?503841-How-to-Convert-MonthName-to-Value(Microsoft-access-2003)
So what I did was have a Query which pulled out the DISTINCT months from my table. Then in the design view i added another column with MonthNo: Month(CDate("1 " & [Month]))and sorted the query on this column
hope this helps someone if not the OP.