How can calculated variance between months with MDX - ssas

I want calculated variance of PeriodsToDate between months with MDX.
For calculate Sum Amount i use thsi query : SUM(PERIODSTODATE( [DATE].[MONTH].[All],[DATE].[MONTH].CurrentMember),
[Measures].[AMOUNT])
I want the result of column "%Varicance_Amount_Month"
Thank you !

Related

How To Have Recursive sum in MDX?

I need to have calculated member in mdx to calculate recursive sum
that should summarize itself with the previous member
You can use the following examples. One is for running total the other one is a bit diffrent.
Cumulative Sum/ Running Total | MDX
MDX Difference between dates non null and of the same dimension

Median function in MDX (Pentaho Mondrian)

I am trying to implement the Median function in MDX. In particular I want to calculate the median of the measure "Amount" for every member of the dimension "Region". For this, I first wrote the following MDX query:
with member [measures].[X] as median([Regions].members, [measures].[Amount])
select {[Regions].members} on rows,
{[measures].[X]} on columns
from [product]
However the above query will calculate the average "Amount" for every member of "Region" and then return the median of these (average) values.
To fix the issue I rewrote the above query using a "Productid" dimension that assigns a unique id to each product of the cube:
with member [measures].[X] as median([productid].members, [measures].[Amount])
select {[Regions].members} on rows,
{[measures].[X]} on columns
from [product]
The above query correctly returned the median "Amount" values for every member of "Region". The problem is that the query seems to be computationally expensive and it hangs. I was wondering if there is a more elegant solution to the problem.

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

Average of sums in MDX query

How can I compute average of sums in MDX? I want to compute sum of spending for each person and then compute an average of it. I have the following query so far, but I believe it gives me wrong result:
WITH MEMBER [Measures].[Average] AS
AVG(Measures.cost)
SELECT [Measures].[Average] ON COLUMNS
FROM
( SELECT Measures.cost ON COLUMNS,
{Person.[Last name].MEMBERS}*
{Person.[First name].MEMBERS} ON ROWS
FROM Cube )
Any help would be greatly appreciated.
You just need to put in the first argument of Avg the set of your persons.
WITH MEMBER [Measures].[Average] AS
AVG(Person.[Last name].MEMBERS * Person.[First name].MEMBERS, Measures.cost)
SELECT [Measures].[Average] ON COLUMNS
FROM Cube
Try to create a calculated measure for this function like this
IIF (([Measures.cost] > 0), AVG(Person.Members,Measures.cost),null)
Then use this calculated measure in your MDX query
SELECT Person, 'calculated.measure'
FROM Cube
This is only a sample code to illustrate the function.

MDX and AVG function

Not sure if this is the right place for MDX question but it seemed to be the most appropriate.
I have a question about MDX and the AVG function.
I would like to compute the average sale amount by day across several month for a year.
So I would like to compute the AVG of the 2010/01/01, 2010/02/01, 2010/03/01, etc... and this for everyday of the month.
Can anyone give me a hint on how I'd be able to do that ?
I would go for something that looks like this
WITH MEMBER [Measures].[Total] AS AVG(DESCENDANTS([Time].[2010], [Day]),[Measure].[Sale])
Thank you,
UPDATE
I have open a new question with a clearer explanation of my problem and study case.
Please find it at : MDX: avg advanced use
You are on the right track. You can compute the average with:
WITH
MEMBER [Measures].[Average Sales] AS
AVG(DESCENDANTS([Time].[Calendar].CurrentMember,
[Time].[Calendar].[Date]),
[Measure].[Sale])
SELECT
{
[Measures].[Average Sales]
} ON 0,
{
[Time].[Calendar].[Month]
} ON 1
FROM [YourCube]
This will give you the average for each member of the Calendar hierarchy of the Time dimension which you select. It will work for Years, Quarters, Months, etc and will average the Sale measure over days under the specified members. In your case you can just select Month on ROWS or COLUMNS as shown in the code sample.