Design OLAP cube and MDX query for my needs - mdx

I have an OLAP cube with a time dimension [year > month > day month > hour]. Now I need to create some reports very fast such as report for all sales of yesterday (like: 07:00 AM - 265 sales), all sales for last month (like: 1st February 2013 - 6625 sales), and it's all goig easy & fast because for the yesterday I'm querying: "WHERE {Hierarchize({[Date].[2013].[2013-2].[2013-2-1]})}" and for the month I'm querying :"WHERE {Hierarchize({[Date].[2013].[2013-2]})}".
But now I need also to create a report for the last 30 days. Any ideas how can I make this report as fast as the last month report? Thanks!

You need to look at the CurrentDateMember function, see Diethards blog here for a comprehensive explanation:
http://diethardsteiner.blogspot.co.uk/2009/10/current-date-function-on-mondrian.html
As for performance - the only solution is to turn on the various mondrian logs, and check that firstly there is no slow SQL - if there is then fix that in the database first - chances are a missing index or something.
Finally if it's still slow then post the full mdx. You dont have 2 separate date sets do you?

Related

Group data by weeks since the start of event in sql

I’m a data analyst in the insurance industry and we currently have a program in SAS EG that tracks catastrophe development week by week since the start of the event for all of the catastrophic events that are reported.
(I.E week 1 is catastrophe start date + 7 days, week 2 would be end of week 1 + 7 days and so on) then all transaction amounts (dollars) for the specific catastrophes would be grouped into the respective weeks based on the date each transaction was made.
Problem that we’re faced with is we are moving away from SAS EG to GCP big query and the current process of calculating those weeks is a manually read in list which isn’t very efficient and not easily translated to BigQuery.
Curious if anybody has an idea that would allow me to calculate each week number in periods of 7 days since the start of an event in SQL or has an idea specific for BigQuery? There would be different start dates for each event.
It is complex, I know and I’m willing to give more explanation as needed. Open to any ideas for this as I haven’t been able to find anything.

Q > SQL Business days for specific month/region

I am trying to write a sql query that would automate my reporting, I am pulling total renewal volume for month X and dividing it by the # of business days for that specific month (manual process for now). The issue that I am having and cannot seem to solve is that I report on two centers (Toronto & Montreal) and these two cities do not share the same holidays so depending on the month the # of business days will vary between cities.
The solution that I can think of is making a table within sql manually with a year or two ahead of the holidays for these 2 cities then sourcing the table, unless anyone else can suggest something better :).
Thanks in advance

How to store availability information in SQL, including recurring items

So I'm developing a database for an agency that manages many relief staff.
Relief workers set their availability for each day in one of three categories (day, evening, night).
We also need to be able to set some part-time relief workers as busy on weekly, biweekly, and in one instance, on a 9-week rotation. Since we're already developing recurring patterns of availability here, we might as well also give the relief workers the option of setting recurring availability days.
We also need to be able to query the database, and determine if an employee is available for a given day.
But here's the gotcha - we need to be able to use change data capture. So I'm not sure if calculating availability is the best option.
My SQL prototype table looks like this:
TABLE Availability Day
employee_id_fk | workday (DATETIME) | day | eve | night (all booleans)| worksite_code_fk (can be null)
I'm really struggling how to wrap my head around recurring events. I could create say, a years worth, of availability days following a pattern in 'x' day cycle. But how far ahead of time do we store information? I can see running into problems when we reach the end of the data set.
I was thinking of storing say, 6 months of information, then adding a server side task that runs monthly to keep the tables updated with 6 months of data, but my intuition is telling me this is a bad fix.
For absolutely flexibility in the future and keeping data from bloating my first thought would be something like
Calendar Dimension Table - Make it for like 100 years or Whatever you Want make it include day of week information etc.
Time Dimension Table - Hour, Minutes, every 15 what ever but only for 24 hour period
Shifts Table - 1 record per shift e.g. Day, Evening, and Night
Specific Availability Table - Relationship to Calendar & Time with Start & Stops recommend 1 record per day so even if they choose a range of 7 days split that to 1 record perday and 1 record per shift.
Recurring Availability Table - for day of week (1-7),Month,WeekOfYear, whatever you can think of. But again I am thinking 1 record per value so if they are available Mondays and Tuesday's that would be 2 rows. and if multiple shifts then it would be multiple rows.
Now and here is the perhaps the weird part, I would put a Available Column on the Specific and Recurring Availability Tables, maybe make it a tiny int and store something like 0 not available, 1 available, 2 maybe available, 3 available with notice.
If you want to take into account Availability with Notice you could add columns for that too such as x # of days. If you want full flexibility maybe that becomes a related table too.
The queries would be complex but you could use a stored procedure or a table valued function to handle it fairly routinely.

How to get a subquery total in SSRS

I'm new to SSRS because I'm needing to do some more complex reports that are getting increasingly difficult/impossible in Crystal Reports. The initial report I'm working on involves getting a Trailing-Three-Month total for sales by salesperson grouped by week. Given a date range and a selected salesperson, I can get the basic report done with total sales grouped by year and week number (1-52).
However, for each of those weeks, I need to get the total sales for the 13-week period ending with that week. For example, for week # 20 - I need to show the total sales for weeks 8-20. On week # 21, I need to show the total sales for weeks 9-21. Etc.
I've managed to do some date formulas to calculate the starting & ending dates of the three month period. But what is the preferred way to get the subtotal of sales into the main report? In Crystal Reports, there was a way to pass a value from a subreport into the main report. But from what I understand, you can't do that in SSRS - subreports are "display only". Eventually, I will need to graph the TTM amount.
I've tried several methods, but I want to know what the best way is to get these kind of values? If I were writing code, it would just be nesting Do-While loops. What is the best method as far as complexity and/or performance?

Speed up Running Total MDX calculated measure?

I'm using the follow mdx to keep a running total of the Period Balance measure in my cube:
SUM({[Due Date].[Date].CurrentMember.Level.Item(0):[Due Date].[Date].CurrentMember}, [Measures].[Period Balance])
It works great, however it's really slow as the amount of data displayed increases. I can't use a MTD or YTD because the users may be analyzing data that overlaps years. Any way I can speed this up?
Thanks in advance.
I take it you've seen this? http://sqlblog.com/blogs/mosha/archive/2006/11/17/performance-of-running-sum-calculations-in-sp2.aspx
Failing that, there is another sample which uses the technique of taking the parent's prior totals and the parent's current child from first sibling to current - So you'd sum the prior months and then this month's days - That'll only work if you have a date hierarchy though:
http://www.ssas-info.com/analysis-services-articles/62-design/367-inventory-management-calculations-in-sql-server-analysis-services-2005-by-richard-tkachuk
I think the pictures there explain it better, its the "Summing Increments" section.
Are you query-logging and doing usage-based aggregations?