I have a SSAS cube in which there is a measure that needs to be allocated via a percentage located in another measure. I have all this set up as a Measure Expression in my "Equity Amount" measure and it works great.
My problem is that this "Equity Amount" measure is actually a snapshot so I would need it to aggregate using the LastChild function. It turns out that you cannot have a measure expression in a semi additive measure so i'm trying to fake the LastChild function in MDX.
I've seen a lot of examples everywhere on the web and all but none of them talk about having multiple hierarchies in the date dimension. I have both "calendar Year" and "Fiscal Year" hierarchies.
My MDX works for one hierarchy but as soon as I scope for the second hierarchy, the first one gets overwritten. I'm guessing I need to treat both hierarchies in a single statement but am having a real tough time getting it to work.
Here is my MDX for one hierarchy. Can anyone help modify it for multiple hierarchies or is there any other way to solve my problem ?
Scope([Measures].[Equity Value]);
This = iif(isleaf([Calendar].[By Calendar Year].CurrentMember),
[Measures].[Equity Value],
([Calendar].[By Calendar Year].CurrentMember.LastChild,[Measures].[Equity Value]));
End Scope;
David,
1) You're using scope as a calculated member. You can get rid of your iif by declaring the scope working only in a sub-cube :
scope ([Measures].[Equity Value],[Calendar].[By Calendar Year].levels(0).... )
This = (the expression)
2) Not sure to understand your problem but a tuple with two members of two hierarchies of the same dimension can be null by construction: As an example your first day of the calendar (1/1/2010) and the first day of your fiscal calendar (e.g. 1/6/2020) are not the same day so actually null. Two hierarchies of a same dimension are only ways of representing the same coordindates (here days), you're doing an intersection by declaring a tuple.
Not sure I'm helping you...
Thanks for trying! I understand what you mean (I think). MDX is one tough language!
I ended up doing the allocation via the view that is the source for my measure and keeping the LastChild aggregation function for the measure. In the end, it is much easier and also is better for query performance.
Thanks anyway :)
Related
I require some more advanced MDX knowledge than mine.
I need to get the RepoRate_MAX for repo products, at book and instrument level, but also looking at the Java code I'm replacing that code always uses the max MurexId.
How can I perform the below (I've placed MAX in here on the dimension but this is wrong) and I need the combo of the dimensions and also the MAX MurexId:
[Measures].[RepoRate_VAL] = (([Deal].[ProductType].&[REPO],[Deal].[Book],[Deal].[Instrument],MAX([Deal].[MurexId])),[Measures].[RepoRate_MAX])
I'm sure it's a simple one but my mind is part way between the Java OO and MDX worlds currently haha :D
Thanks
Leigh
So after some experimenting I found out about the TAIL and Item MDX functions.
I think at one point I did get it working, but didn't make a note of what did work. I was playing around with this and variants of it..but most versions ended up in unusable query times:
[Measures].[RepoRate_VAL] = (([Deal].[ProductType].&[REPO],[Deal].[Book],[Deal].[Instrument],TAIL(EXISTING([Deal].[MurexId].[MurexId])).Item(0)),[Measures].[RepoRate_MAX])
So I then decided to push the RepoRate calculation back to the SQL data preparation script. Cleaner/smoother data is always better and then to have simple calculated members.
I used SQL to determine the RepoRate from tradelevel with MAX(MurexId) and GROUP BY on Book, Instrument to then update my main fact table to ensure that the correct RepoRate was set at Book, Instrument level.
Thus the calculated member is then:
[Measures].[RepoRate_VAL] = (([Deal].[Book],[Deal].[Instrument]),[Measures].[RepoRate_MAX])
Fast data prep and a fast calculated member on the Excel/Pivot/UI layer.
here is my case. I have small training in creating OLAP cube in SSAS and as part of it I need to calculate median time from creation issue to resolve issue.
So according to microsoft docs I should use MEDIAN function in MDX. So here is my code:
MEDIAN([Issue].[Issue ID],[Measures].[Hours Resolved])
Short explanation: [Measures].[Hours Resolved] it's a measure calculated in database from dimensions "resolved issue time" - "creation issue time" with DATEDIFF function. Both are smalldatetime datatype.
And it looks like it works in proper way for case on the screen below.
Exept "Grand Total" value in Mediana column.
I believe that Grand Total value should be 12 becasue this is proper score according to way the median should be calculated (checked also in Excel). So am I wrong here and this is proper behaviour? Or maybe I miss something in my calculation or configuration in SSAS?
Second case in this exercise.
When I will add for example Group Name column like on the picture below:
In my understanding value mediana column for let's say CRM part should be 9.
Can you please guide me if I'm right or wrong? If I'm right how to achieve this. Or if I'm wrong please point mistake in my solution. This is my 1st time when I'm calculating median.
It's a little embrassing that no one even look at it - 16 views and probably all mine - well doesn't matter anymore because I figured it out myself.
For proper median calculation for all dimensions I should use Median function and Scope function in MDX. So here is the code if someone will face the same problem in future:
CREATE MEMBER CURRENTCUBE.[Measures].[Median]
AS Null
VISIBLE = 1;
SCOPE([Measures].[Median]);
THIS = MEDIAN([View Issue Median].[Issue ID].[Issue ID], [Measures].[Hours Resolved]);
END SCOPE;
Scenario
Designing a Star Diagram for an OLAP environment for the process Incident Management. Management requests to be able to both filter on SLA status (breached, achieved or in progress) and being able to calculate the percentage of sla achieved vs breached. Reporting will be done through in Excel/SSRS through SSAS (tabular).
Question
I’m reasonable inexperienced in designing for an OLAP environment. I know my idea will work but I’m concerned this is not the best approach.
My idea:
SLA needs to be both a measure and a dimension.
DimSLA
…
(Nullable bool) Sla Achieved -> Yes=True, No=False, and InProgress=NULL
…
FactIncident
…
(Nullable Integer) Sla Achieved Yes=1,No=0 and In Progress=NULL
…
Then in SSAS, publish a calculated percentage field which averages FactIncident-SlaAchieved.
Is this the right/advisable way to do it?
As you describe it, "SLA achieved" should be an attribute, as you want to classify by it, not sum it. The only thing you want to sum or aggregate would be other measures (maybe an incident count) under the condition that the "SLA achieved" attribute has certain values like "achieved" or "not achieved". This is the main rule in dimensional design: Things you use for classifying or break down are attributes, and things that you calculate are measures. There are a few cases where you need a column for both, but not many.
Do not just use a boolean value. Use a string value easily understand by users like the texts "SLA achieved", "SLA not achieved", "in progress". This makes it much more easy for non technical users to use the cube. In case you use this in a dimension table , there would be just three records with the strings, and the fact table would reference them with maybe a byte foreign key, hence more meaningful texts do not use up millions of bytes.
How do I create custom rollup types in icCube?
Say, I need WAvg (which is already implemplemented there) instead of plain Avg function. But I it is not on the dropdown list in measure creation form. What should I do now?
Alexander, I assume you're talking about the cube builder.
The weighted-average is not available in the list of available aggregation types because there's no straitforward way to implement it at cube level. Aggregation types available for standard measures are simple calculations. Those calculation are meant to be very fast for millions of rows. You've two kinds of average available for standard measures : 'average on leafs(rows)' and 'average on children', which might be near what you're looking for.
In the case of a weighted average you have to create a calculated measure: you need to defined the values to "weight" your underlying measure against. The documentation weighted-average is giving several examples.
Is there such a thing as a constant in SSAS?
Example (this is really happening where I'm at) everyone agrees that gigs to mb be converted by 1000 (not 1024) and tb to mb by 1000000.
Where would you store a number like that used across the board?
If it's inside the cube, could you create a calculated member that stores it? Define it in the cube's calculation script, it's fine with constants in there.
In cube calculation script:
CREATE MEMBER CURRENTCUBE.Measures.MBtoGigs AS 1000
Query against the cube:
SELECT Measures.MBtoGigs ON COLUMNS FROM [Cube]
One possible pitfall I would point out, is that using constants like this can alter the way you'd expect the NON EMPTY behaviour to work in your queries - As a constant is never 'empty'.
Having said that, you can define you own non-empty-behaviour for calculated measures, so remember to try that with any calculated measures that involve constants if you experience any issues.
where\how do you need to use it?
you can always create a fact table with a column with that value (1000), whitch will become a measure group, and set the aggregation type on the measure with to "lastNonempty".
Since this value is on its own MG it can be easly used on the expression property of another measure on a different MG