How To Have Recursive sum in MDX? - ssas

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

Related

How can calculated variance between months with MDX

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 !

SSAS (Tabular) / DAX - Calculate measure over time / Rolling distinct count

I've a question about a rolling distinct count. I'm trying to calculate the latest 30 weeks (210 days) from a specific date (eg. Specific date = 18-02-2019 distinct count from 23-07-2018).
I've found a website/blog where this is explained, https://radacad.com/datesinperiod-vs-datesbetween-dax-time-intelligence-for-power-bi. But in some weird way, my calculation is not working.
My DAX expression:
Aantal mutaties afgelopen 30 weken:=
CALCULATE(
DISTINCTCOUNT(FCT_KlantReis_Mutatie[Mutatie]);
DATESINPERIOD(
FCT_KlantReis_Mutatie[Mutatiedatum];
LASTDATE(FCT_KlantReis_Mutatie[Mutatiedatum]) ;-210;DAY)
)
But in Excel (and PowerBI) I get the following result:
The table is linked to a date dimension. My guess is that it must be posible, but how...
Thanks in advance for the help.

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?

MDX expressions to aggregate data at certain level for calculated member

For now sometimes I have problems with creating difficult calculated members in SSAS. Is it possible to make case which will SUM certain measure on certain level when user choose another certain level of dimension? For example we have standard time dimension with 4 levels:
Year
Month
Week
Day
Also we have some measure orders which have default function SUM in properties.
Which case do we need to calculate this: sum all orders in week which including current day which we have chosen already.
Also could you recommend me some nook or source for level up my mdx knowledge?
Thanks a lot.
Yes, it's possible, when you use MDX functions, which are connected with levels.
Here is an example with Year > Quarter > Month > Day hierarchy:
Use MDX calculated member to have a SUM of upper level member children (including selected one):
The same if you want to create calculation inside the cube:
CREATE MEMBER CURRENTCUBE.[Measures].[SameLevelMembers]
as SUM({[Report Date].[Report Date].CurrentMember.Parent.Children},[Measures].[Count]),
VISIBLE = 1 ;
And a result in cube browser:
Hundreds of articles you can find there: http://ssas-wiki.com/w/Articles#MDX
I also like this one: http://mdxpert.com because of well-structured info.

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.