Summing of averages - ssas

SSAS 2012, AdventureWorks Tabular Model SQL 2012
Having a hierarchy of some fields, want to list values from a measure per month in a year, then see average value for month, then sum these averages on all hierarchy levels up.
Example: (all measures in table 'Internet Sales')
ComplexCalculation:=[Internet Total Sales]*[UnitPriceAvg]/1000
UnitPriceAvg:=AVERAGE('Internet Sales'[Unit Price])
AvgComplexCalculation:=AVERAGEX(VALUES('Date'[Month]), [ComplexCalculation])
AverageAndSumComplexCalculation:=IF( ISFILTERED(Product[Product Name]), [AvgComplexCalculation], SUMX (VALUES (Product[Product Name]), [AvgComplexCalculation]))
Pivot Fields:
Filters: [Calendar Year] [2006]
Rows: [Product Category Name],[Product SubCategory Name],[Model Name],[Product Name],[Month]
Columns:
Values: [AverageAndSumComplexCalculation]
Is it the right way of doing this? Noticed that when my "ComplexCalculation" measure becomes more and more complex it needs lot of time to calculate the values (causes timeout).

Related

MDX - Calculations of Daily Stock (Financial Instrument) Values

How do I calculate the daily values of a Persons Stock (Financial Instrument) using MDX.
A person buys Microsoft Shares/Stock like in the example below. I already have a SSAS MD Cube with this Information (DimDate, DimShare, FactInvestment, DimClient).Fund Units
Can easily calculate the Daily Balance of Units (Unit Balance) using MDX (sum(NULL:[Date].[Calendar].CurrentMember,[Measures].[Units]) to give me daily Balance of Units.[Daily Stock Value][2]
I have a Daily Share price Measure Group with a "Share Price" with Aggregation Usage Last non-empty value. This will give me the daily Stock price.[Daily Stock Price]. The Measure group DOES NOT have a Client dimension.[Daily Stock Price][3]
Would like to calculate the daily value of stock [Unit Balance]*[Share Price] = [Share Values] for each clientDaily Stock Values. See manual calculations in yellow on Pivot Table.

Calculated member to get dimension value in previous year

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])

Using percentile as measure in SSAS

How do I use percentile (let's say 99% percentile) as a measure in SSAS cube? I'd like to be able to report on it using many different dimensions and filters so pre-calculating in sql is not an option.
If you want to evaluate percentiles over a dimension, then you can do it without having to pre-calculate anything in SQL. This can be done using a combination of the TopPercent and Tail MDX functions.
For example, say you want to find the 25th percentile over a [Date].[Calendar Month] dimension attribute by the [Measures].[Avg Daily Census] (I work in health care) measure. You could use the following query to do this.
WITH
MEMBER [Measures].[25th Percentile] AS
(
Tail(
TopPercent(
[Date].[Calendar Month].[Calendar Month],
100 - 25,
[Measures].[Avg Daily Census]
)
).Item(0),
[Measures].[Avg Daily Census]
)
SELECT
[Measures].[25th Percentile] ON 0
FROM [Census]
This query uses TopPercent to find the top 75 percent of values along the [Calendar Month] dimension attribute, finds the member with the lowest value along that set, and then evaluates the measure at that member.
Now, if you want to generate the entire set of percentile values, you can use a sequence utility dimension (just a dimension containing numbers), or you could create a custom percentile dimension containing 0-99. The following query would generate the values of the measure over all percentages.
WITH
MEMBER [Measures].[Percentile] AS
(
Tail(
TopPercent(
[Date].[Calendar Month].[Calendar Month],
100 - [Sequence].[Ones].CurrentMember.MemberValue,
[Measures].[Avg Daily Census]
)
).Item(0),
[Measures].[Avg Daily Census]
)
SELECT
[Measures].[Percentile] ON 0,
[Sequence].[Ones].&[0] : [Sequence].[Ones].&[99] ON 1
FROM [Census]
However, if you are trying to evaluate percentiles at the grain of the fact table, then I believe you will either need to pre-calculate the percentile values for each fact row or add a degenerate dimension and use the method above.

Merge two MDX resultsets from the same measures group

I am trying to merge the result of two separate MDX queries, where the measures are from the same measure group. The cube design is based on a lifecycle transaction model, where the date are all role playing dimensions. The queries are:
select [Measures].[Issued] on columns,
[Product].[Product Name].[Product Name] on rows
from [MET2DW]
where ([Product].[Product Type].&[IP], [Product].[Component Type].&[SD],[Issued Date].[Fiscal Year Name].&[Fiscal Calendar 2010])
select [Measures].[Last hits] on columns,
[Product].[Product Name].[Product Name] on rows
from [MET2DW]
where ([Product].[Product Type].&[IP], [Product].[Component Type].&[SD],[Last Sync Date].[Fiscal Year Name].&[Fiscal Calendar 2010])
I've tried using a CROSSJOIN, but then it complained about the fact that the measures I was trying to cross join are in the same heirarchy. If I run the query with both the measures on the same set, then the date filters don't really work anymore. The issue is basically that they are different date dimensions for each of those counts, and they slice different ways.....
Is there any way to do this?
You can create a MDX calculated member adding both values for two tuple of different dimensionality (aka same hierarchies):
with
member [Measures].[-Issued] as ([Issued Date].[Fiscal Year Name].&[Fiscal Calendar 2010],[Measures].[Issued])
member [Measures].[-Last hits] as ([Last Sync Date].[Fiscal Year Name].&[Fiscal Calendar 2010],[Measures].[Last hits])
select
{[Measures].[-Issued],[Measures].[-Last hits]} on columns,
[Product].[Product Name].[Product Name] on rows
from
[MET2DW]
where
([Product].[Product Type].&[IP], [Product].[Component Type].&[SD])

MDX Calculating 12 month average unit price and applying to forecast quantity

I have a requirement to show a report which calculates the average selling unit price of each product and then multiplies this average by the number of units forecasted to sell in the next year (for each product).
At this point my main issue is getting this set up so the totals roll up correctly when viewing at product category level. Using AdventureWorks as an example (and sales orders instead of forecasts) I've got this far...
with
member [Measures].[Sales Order Value]
as sum(descendants([Product].[Product Categories].currentMember,
[Product].[Product Categories].[Product]),
[Measures].[Average Unit Price] * [Measures].[Order Count]),
format_string = "Currency"
select ([Date].[Calendar].[Calendar Year].&[2008],
{[Measures].[Sales Order Value] }) on columns,
[Product].[Product Categories].[Subcategory].members on rows
from [Adventure Works]
I think this is about right, I believe this is going down to product level to apply the calculation between product average unit price and any sales orders for the product.
My issue is that I think the average unit price is being calculated over all data, I need to alter this to pick up an average based on the last 12 months only.