Calculated member to get dimension value in previous year - ssas

I am new to BI and need help to create a calculated member.
I have a cube with following dimension and measure:
Dimension tables:
Dim_Time (Year, Month, Day)
Dim_MyValueCollection: DataType with data types having values 'Gross Paid Claims' and 'Gross Written Premiums'
Measure:
FactTable.Value
I need to create a calculated member on Dim_MyValueCollection.DataType to represent the difference of 'Gross Written Premiums' values in current and previous year.

To get data from a previous period in mdx you can use these functions:
Lag
https://msdn.microsoft.com/en-us/library/ms144866.aspx
ParallelPeriod
https://msdn.microsoft.com/en-us/library/ms145500.aspx
Have you attempted any mdx ?
Edit
Here is a general tuple for the change in Gross Written Premiums since the same period in the previous year. I've guessed the names of your dimensions because you have not supplied any sample mdx:
([Time].CURRENTMEMBER, [Measures].[Gross Written Premiums])
-
(PARALLELPERIOD(Year,1,[Time].CURRENTMEMBER), [Measures].[Gross Written Premiums])

Related

SSAS - YTD SUM with other dimension

I would like to have a calculated measure (rolling_sum) that sums up all the values up to a selected month in the year and I would like to be able to query this measure without the date dimension.
So, I have the following calculated member:
SUM(YTD(),[Measures].[Value])
Querying this measure works fine when the query includes the date dimension, however I would like to be able to query this measure by other dimensions without the date dimension.
Would this be possible?

Create MDX to Divide two measures for each month and then sum the all of the months

I have a multidimensional cube that needs a custom measure that I'm not sure how to build.
That data looks like this:
MemberID-----Date-------EventType
1--------------1/1/2016-------1
2--------------1/1/2016-------2
3--------------2/1/2016-------1
2--------------2/1/2016-------2
4--------------2/1/2016-------2
There is a count measure in the cube, but others can be added if needed. I need to create a measure that will use whatever filters the user applies and then count the EventType (1 and 2 only) by month, divide the resulting counts for EventType 1 into the count for EventType 2 (for each month individually), and finally sum the monthly results. For example 1/1/2016 would be 1/1=1 (count of EventType 1 and count of EventType 2) and 2/1/2016 would be 1/2=0.5 so the resulting measure value for the two months would be 1+0.5=1.5. Any help is greatly appreciated.
Let's assume you have a Date dimension with an attribute called Month. And let's assume you have an EventType dimension. And let's assume you have a count measure in your measure group called Cnt. Here's what else you need to do.
First, go to the DSV and add a new calculated column to the fact table which is called NullInt and is the following expression:
cast(null as int)
Then create a new Sum measure in your measure group off that column and call the measure My Rollup. Under the Source property, change NullHandling to Preserve so that it will start off null.
To explain why we're doing this, a scoped assignment to a physical measure will aggregate up. (If you assign a value to a physical measure at the grain of each month, then it will rollup to the grand total.) But a scoped assignment to a calculated measure doesn't roll up.
Then in your MDX script add the following calculations:
scope([Date].[Month].[Month].Members); //calculate at the month level then rollup
[Measures].[My Rollup] = DIVIDE(
([Event Type].[Event Type].&[1],[Measures].[Cnt]),
([Event Type].[Event Type].&[2],[Measures].[Cnt])
);
end scope;
Note that your version of SSAS probably has the DIVIDE function if it's AS2012 with the latest service pack or newer. But if it doesn't, you can always do division the old fashioned way as IIF(denom=0,null,num/denom).

MDX - Applying a month summary value to a dimension

I am trying to apply a measure value calculated at the Month level to a dimension contained within that month i.e.
Should look like this:
I've attempted to use a scoping statement so far but with no luck.
SCOPE (
{[Sale].[Sale Year].&[2]:[Sale].[Sale Year].&[7]}
,[Date].[Calendar Month].&[201603]
,[Measures].[Costs Per Sale] );
THIS = ([Date].[Calendar Month].&[201603],[Measures].[Costs Per Sale]);
END SCOPE;
The Aggregated Sales measure is calculated using the Sale Year which unfortunately has not and cannot be linked to the Cost dimension.
Does anyone know how I can apply the Cost Per Sale monthly value to the [Sale].[Sale Year] dimension?
Thanks
Try this -
SCOPE ({[Sale].[Sale Year].&[2]:[Sale].[Sale Year].&[7]} ,[Measures].[Costs Per Sale]);
THIS = ([Sale].[Sale Year].[All],[Measures].[Costs Per Sale]);
END SCOPE;

SSAS - Count Time Dimension

I looked at this topic, Calculating the number of days in a time dimension node - with Grand Total, but can't seem to get it.
I have a Time Dimension; [Invoice Date].
I want to count the number of Work Days in that dimension for a specified time period. I'm new to MDX.
Here's what I have.
Count(
Descendants(
[Invoice Date].CurrentMember,
[Invoice Date].[Work Date].[Work Date]
)
)
I'm getting a cube error now.
An easy way to implement this reliably would be to create a physical measure "Day Count". To do this, create a new measure group on the Date dimension table, and define "Day Count" as the Count. On the dimension usage tab, make sure you set a relationship from this measure group to the Invoice Date cube dimension and not the other dimensions.

MDX Select measures between two values

I have a fact table which stores for each record an init_year and end_year as integers, which refer to the year range in which the record is valid.
In which way I can design a MDX query to select my measures (count) for each year, in order to have a trend of my measures over year?
THANKS
I'm not sure this should be done in MDX.
This sort of thing is usually calculated in the fact tables (linked to a dimension table of all available years), and a new measure is created. No calculation would be done in MDX; you'd just display the new measure.
Having said that, I've just Googled "MDX count start end date" and found www.purplefrogsystems.com/blog/2013/04/mdx-between-start-date-and-end-date which suggests you use the LINKMEMBER function. Their example code was...
AGGREGATE(
{NULL:LINKMEMBER([DATE].[Calendar].CURRENTMEMBER
,[START DATE].[Calendar])}
* {LINKMEMBER([DATE].[Calendar].CURRENTMEMBER
, [END DATE].[Calendar]):NULL}
, [Measures].[Project COUNT])
...or...
AGGREGATE({NULL:[DATE].[Calendar].CURRENTMEMBER}
, [Measures].[Project COUNT])
...but it needs careful reading!