I have the following MDX query that calculates members and then selects those members for a specified date range:
WITH
MEMBER [Measures].[Prior] as ([Date Post Transaction].[Calendar Month Period].CurrentMember.Lag(12),[Measures].[Unique Patients])
MEMBER [Measures].[Current] as [Measures].[Unique Patients]
SELECT {[Measures].[Current],[Measures].[Prior]}
DIMENSION PROPERTIES PARENT_UNIQUE_NAME , HIERARCHY_UNIQUE_NAME ON COLUMNS , NON EMPTY Hierarchize(AddCalculatedMembers({DrilldownLevel({[Date Post Transaction].[Calendar Month Period].Children})}))
DIMENSION PROPERTIES PARENT_UNIQUE_NAME , HIERARCHY_UNIQUE_NAME ON ROWS FROM (SELECT ({[Date Post Transaction].[Calendar Month Period].&[201207],[Date Post Transaction].[Calendar Month Period].&[201208],[Date Post Transaction].[Calendar Month Period].&[201209],[Date Post Transaction].[Calendar Month Period].&[201210],[Date Post Transaction].[Calendar Month Period].&[201211],[Date Post Transaction].[Calendar Month Period].&[201212],[Date Post Transaction].[Calendar Month Period].&[201301],[Date Post Transaction].[Calendar Month Period].&[201302],[Date Post Transaction].[Calendar Month Period].&[201303],[Date Post Transaction].[Calendar Month Period].&[201304],[Date Post Transaction].[Calendar Month Period].&[201305],[Date Post Transaction].[Calendar Month Period].&[201306]})
ON COLUMNS FROM [cube])
WHERE ([Provider Billing].[Specialty Mgma Pcps].&[Cardiology: Inv-Intvl])
Basically, this query is asking for all patients within Cardiology for the current date range and prior date range by month.
This query takes 8-9 seconds to run, which is crazy. I'm using Analysis Services to run and test query times and have not ran into other tools to help optimize MDX. So my first question is, does anyone know of such tools to help optimize MDX?
My main question is what method or structure should I be using in the query to help process the results faster? I originally was not using the .lag() function and instead running a query that included each month for current and prior. I did see improved result times from this switch.
I have several reports that use this same format, just different metrics (MEASURES) and so you can imagine the load times we're getting with queries that each run 5+ seconds.
Generally, MDX optimization is not easy, there is not much information what causes which performance impact and few information like SQL plans, and what is there is not documented well. What is there, however:
Microsoft has a performance optimization guide: http://technet.microsoft.com/en-us/library/dd542635(v=sql.100).aspx
The former chief developer of MDX and the Analysis Services query engine had a blog: http://sqlblog.com/blogs/mosha/
He also developed a tool that you can use to run a query and see some more or less useful query statistics which can still be downloaded: http://www.sqlbi.com/tools/mdx-studio
Looking at your query, I would not be sure where the performance killer is. Maybe something in the calculation script which is not visible in the query itself. What I would try first would possibly be - depending on the structure of your [Date Post Transaction].[Calendar Month Period] hierarchy - just using something like
[Date Post Transaction].[Calendar Month Period].&[201207] : [Date Post Transaction].[Calendar Month Period].&[201306]
for the rows axis, and omitting the subselect altogether, i. e. use just
FROM [cube]
as the whole FROM clause without any subselect. But I would doubt this will dramatically decrease run time.
Related
I am a newbie at Tableau (thought I have spent years working in R and Python), seems to be different in the way it handles things or I'm just not thinking the right way.
I have a data sources with training data (employees training and the status). The point is to build a dashboard that shows the % of training that is overdue. I have all of the logic for it, but I am stuck on something.
I have a calculated field to show me the total training due, then when I put that in a table, with a filter by year and a breakdown by month, I get the totals by month - good deal.
Now, I need to perform an year calculation (not the months, but the year based on a few different things), so my first step is I need to get the "Total Training Due" for December 2018. I have a dimension called "Due Month" which is a numeric (1,2,3,4, etc.) representing the month. So, based on what I have observed, I just need to do a little IF statement like so (keep in mind this is only for 2018 data right now):
IF [Due Month] = MAX[Due Month] THEN COUNT[Employee ID] END
I know this isn't the exact context, but it's sort of what I am looking for. So, for 2018, it would mean that, for all rows that are of month 12, I want to count those up (each row is a unique training requirement) and I want the total for the latest month in the data set. My overall goal is to create the calculation I need in a new sheet with a single calculated field (See the image below of the Excel spreadsheet and the J10 calculation). Then I can use a dashboard to combine everything. I thought about a total row at the bottom, but there isn't enough ways to change the totals to customize it to what I need. I figured I dashboard was the way to go and replicate each part it its own sheet.
I have seen so many suggestion for things like this, but not exactly this. I have tried many, but nothing that works. Here is the spreadsheet I am trying to replicate:
As you can see that calculation in J10 is kind of weird, no biggie for Excel, but I am struggling to replicate this in Tableau. Here is what I have in my Tableau so far, I'm 90% of the way there, I just need that last calculation. I have replicated the main table, and figure I'll do this J10 calc on a new sheet and just put them together on a Dahsboard. The only thing is, I want this to work when new data comes in, so I don't want to hard code any month numbers in there, I want it to be dynamic. Here is what I have on the tableau so far:
Thanks in advance!!
To get the value in Tableau that you have in F11 it's:
{FIXED [Due Year] : sum([Incomplete Overdue])}
You should be able to create that as another calculated field and then reference it, or include it directly in the Total Past Due Rate calculation.
This is an LOD calculation, the [Due Year] means that you only want the result dimensioned by the [Due Year] dimension, so you will get a different result for each year in the data source.
Thanks for this - after posting this, I was able to come up with this:
(TOTAL([Incomplete Overdue]) + SUM(IF ([Past Due]<0 AND INT([Due Month]) = {MAX(INT([Due Month]))}) THEN 1 ELSE 0 END)) / COUNT(IF INT([Due Month]) = {MAX(INT([Due Month]))} THEN [Employee ID] END)
Which works for the basic result I was looking for.
I want to summarize figures for the previous year based on multiple possible selections in Year, Month and Day to provide a previous year comparison on my dashboard: see screenshot.
I have found plenty of working examples for previous year summaries applied to a fixed dimension but none to assist with providing a summary for a range of possible selections.
I have tried numerous set analysis expressions so far, and I have tried adding a variable which calculates 1 year prior and including it in expressions, but the difficulty has been where to include the '1' or select from all possible records in the expression.
Most recent attempt as below calculates but returns 0.
sum( {$<Discharge= {$(#vPrevYr)}>}daycase)
Can anyone assist?
Found the solution:
Changed the variable to
vYearMinus1= Discharge_Year-1
Used in expression
sum({$}daycase)
All hunky dory, selections all (multiple or other) produce previous years figures: Yay!
Table from which figure will be extracted includes the year dimension: see attached screenshots Table including dimensions and finished result Finished result
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?
My problem is that I need to calculate a running total that works like a YTD.
The "year" in question is not a calendar year, it is an academic period.
TOTALYTD(..."28-02") nearly does the trick, however on leap years the 29th of Feb bleeds in to the next year's window.
I've tried CALCULATE(MyMeasure, DATESBETWEEN(...,...)) and this doesn't seem to work or I am just using the functions incorrectly.
To summerise, I need an expression that works exactly like TOTALYTD() but does not have the leap yer problem.
Thanks!
Unfortunately, I also experienced the same problem.
I created a dates table with a check to see if the year is a leap year.
Then I created this Dax Formula: Year End = IF(MAX( Dates[LeapYear] )=0,"02/28","02/29")
This worked perfectly, but if I add this to the TOTALYTD built-in formula like this Sales YTD = TOTALYTD( [Sales], Dates[Date], ALL( Dates[Date] ), [Year End]), it does not allow it - which is stupid - hopefully, they will allow this in the future.
I then found this answer, which answers your question but also doesn't because Power BI does not cater for it yet.
"You will need to write custom YTD measures instead" as per OwenAuger
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?