Convert DAX to MDX - ssas

please can someone tell me what the equivalent of the dax query-->MDX
calculate( sum([Measures].[Poids Total]) ,ALL([Dim1].[Id Df])))

At its simplest in MDX it might just be a tuple of the measure and the ALL member of the respective hierarchy:
(
[Measures].[Poids Total],
[Dim1].[Id Df].[Id Df].[All]
)

Related

Calculated Measures - Beginning balance

I am a newb when it comes to MDX so please bear with me as I try to explain this.
I have cube with a measure for cost [Measure].[Cost] and the query is setup with a time parameter to obtain the total cost up to that point in time. #ToAcctDate and is used in the FROM statement as such:
FROM (SELECT (STROSET(#ToAcctDate, CONSTRAINED)) ON COLUMNS
but I would like to get the PREVIOUSMEMBER if possible and to something like
WITH
MEMBER [Measures].[PriorPeriod] AS
SUM( (STROSET(STROSET(#ToAcctDate, CONSTRAINED).PREVMEMBER), [Measures].[Cost])
so that I can then have both the YTD costs as of #ToAcctDate and the YTD Costs at the beginning of the period [Measures].[PriorPeriod] in the same query without unions. is this possible? and if so, is this the right approach?
Maybe along the lines of this?
HEAD will find the first member of the set which you can then apply PREVMEMBER to:
SUM(
HEAD(STROSET(#ToAcctDate, CONSTRAINED)).ITEM(0).ITEM(0).PREVMEMBER)
, [Measures].[Cost]
)

SSAS MDX - PeriodsToDate not working when user selects multiple dates

I've build a MDX calc member that give me the year-to-date (YTD) for budget, however if the user selects multiple months, it returns the total for year. Which I believe is CurrentMember function, but how do it I get the max from the set?
Aggregate(
PeriodsToDate(
[Date].[Fiscal].[Fiscal Year]
,[Date].[Fiscal].CurrentMember
)
,[Measures].[Budget]
)
So when we have a month slicer to select the month, if the end-user selects more then 1 month, then the CurrentMember fails and the parent is used, so the Full Year (FY) is used.
It might be very late to answer this question but hopefully someone else can benefit with the answer.
for this particualr problem you have to create a dynamic set and apply scope to that. check the below MDX.
dynamic set : existing PeriodsToDate(Date].[Fiscal].[Fiscal Year],[Date].
[Fiscal].CurrentMember)
calcualted member : Aggregate( PeriodsToDate( [Date].[Fiscal].[Fiscal Year]
,[Date].[Fiscal].CurrentMember
)
,[Measures].[Budget]
)
apply scope to it scope (Date].[Fiscal].[Fiscal Year],,[Measures].[Budget])
this = aggregate (([dynamic set],],[Measures].[Budget])
end scope
this way u can select a date range without any problem
Kind Regards
mah

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!

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.