Get the descendants of a member - ssas

This request always displays '1' in the column 'nb', but I know that for this patient, the number is '3':
WITH
member pat1 AS [DimTransfusion].[TransfusionPatients].[PatientId].&[{09B7106A-xxxx-4B88-80D6-D1283FE990D6}]--83
set transfusPat AS Descendants(pats1,2)
MEMBER nb AS count(transfusPat)
SELECT {nb} ON 0
FROM [BDD PBM]
but this request displays the correct result:
WITH
member pat1 AS [DimTransfusion].[TransfusionPatients].[PatientId].&[{09B7106A-xxxx-4B88-80D6-D1283FE990D6}]--83
set transfusPat AS Descendants([DimTransfusion].[TransfusionPatients].[PatientId].&[{09B7106A-FB68-4B88-80D6-D1283FE990D6}],2)
MEMBER nb AS count(transfusPat)
SELECT {nb} ON 0
FROM [BDD PBM]
I can't understand why using a member variable instead a real value gives a wrong result.
Here is the dimension usage screenshot:
where VPARCOURS and VTRANSFUSION are fact tables(a Transfusion is always related to one VPARCOURS):
thank you.

The problem was due to pat1: being a member, I suppose the Descendants function returns a member of its first argument is a member, and the same for sets:
so the correct declaration is:
set pat1 AS [DimTransfu...

Related

How to tuple with Member_Key MDX SSAS?

I want to tuple using member key of [Dim].[Country]
{[Dim].[Country].CurrentMember.Member_Key},
STRTOSET("[User].[ID].&[" + mid(username, instr(username, "\")+1) + "]")
But when I use CurrentMember.Member_Key function I get the following error:
The function expects a tuple set expression for the 1 argument. A string or numeric expression was used.
If I write it like this using "members" is works. But then it will tuple with the full name (100 - Norway) but my goal is to tuple it with just the key part e.g "100"
{[Dim].[Country].members},
STRTOSET("[User].[ID].&[" + mid(username, instr(username, "\")+1) + "]")
Best regards,
Rubrix
Instead of [Dim].[Country].CurrentMember.Member_Key you should do something like this:
with member [Measures].CountryKey as [Dim].[Country].CurrentMember.Member_Key
So something like this could work (on Adventure Works):
with member [Measures].CountryKey as [Geography].[Country].CurrentMember.Member_Key
SELECT ([Measures].CountryKey, StrToSet ('[Geography].[State-Province].Members') )
ON 0
FROM [Adventure Works]

MDX currentMember get me error

This MDX function raise error :
with member measures.x as
(
[Date].[Date].[Date].&[20160101] : [Date].[Date].[Date].currentmember.value
,
[Measures].[current balance]
)
select measures.x on columns,
[Branch].[HeadOffice Branch].[Head Office Code] on rows
from MyCube
Error is :
The CURRENTMEMBER function expects a hierarchy expression for the 1 argument. A member expression was used.
But when I use
[Date].[Date].[Date].&[20160101] : [Date].[Date].[Date].&[20160131]
It works good
why?
This is valid mdx:
[Date].[Date].[Date].&[20160101] : [Date].[Date].currentmember
Although this is not:
WITH member measures.x AS
(
[Date].[Date].[Date].&[20160101] : [Date].[Date].currentmember
,
[Measures].[current balance]
)
It is not valid because round braces (...) signify a tuple but a tuple requires exact co-ordinates so the first argument cannot be a set.
You could add an aggregation such as SUM:
WITH member measures.x AS
SUM
(
[Date].[Date].[Date].&[20160101] : [Date].[Date].currentmember
,
[Measures].[current balance]
)
This is valid mdx but if you do not have [Date].[Date] in context i.e. in the WHERE or SELECT clause then all it is returning is the All member.
Why are you using [Date].[Date].currentmember ?
CURRENTMEMBER works on an attribute hierarchy (in your case [Date].[Date]). So [Date].[Date].CURRENTMEMBER will work.
Also you will need to take out the value selector, as your expression returns a set of dates (member : member returns a set of all the members between those two members).

what's wrong in this code mdx?

I wonder what's wrong in this code?
with
member [CA Espagne] As
((select [Measures].[CA], [[Site].[Pays - Site].[Pays].&[ES]))
select {[Measures].[CA], [CA Espagne]} on 0,
[Temps].[Année - Mois - Jour].[Année].&[20100101].children on 1
from [DistrisysOLAP_Global];
Better to tell us the error you're getting... but I guess you should simply define your calculated member as :
with member [CA Espagne] As ( [Measures].[CA], [[Site].[Pays - Site].[Pays].&[ES] )
then the remaining of the statement looks ok (remove the trailing ; ). Otherwise, here is a page explaining the syntax of the calculated members.

MDX CurrentMember with SSAS 2008 doesn't work as stated by MSDN

First of all I use the SQL Management Studio for this query (no Excel 2007 that seems to have problems):
WITH
SET [Project period dates] AS
{
StrToMember("[Time].[Date].&[" + [Project].[ParentProject].CURRENTMEMBER.PROPERTIES("Project Start Iso") + "]"):
StrToMember("[Time].[Date].&[" + [Project].[ParentProject].CURRENTMEMBER.PROPERTIES("Project End Iso") + "]")
}
MEMBER [Measures].[Test] AS ([Project period dates].COUNT)
SELECT
{
[Measures].[Test]
}
on 0,
NONEMPTY ([Project].[ParentProject].MEMBERS)
DIMENSION PROPERTIES [Project].[ParentProject].[Project Duration], [Project].[ParentProject].[Project Start Iso], [Project].[ParentProject].[Project End Iso]
on 1
FROM
[MyCube]
WHERE
(
[Orgunit].[Orgunit].&[448]
)
This query delivers a list of projects with its three properties and a calculated member that is based upon my calculated set. The properties show the right values, but the calculated member shows always the same: the result of the very first project it should be calculated for.
I don't really understand why, because MSDN says:
The current member changes on a hierarchy used on an axis in a query.
Therefore, the current member on other hierarchies on the same
dimension that are not used on an axis can also change; this behavior
is called 'auto-exists'.
They give examples with calculated members, but I think that should also work with calculated sets, I have read that query-based calculated sets are dynamic by nature. Maybe somebody can tell me if I understood that wrong or what else is my problem here.
The named set are only computed once within a query. That is why your calculated member always return the same value.
You just have to remove the named set from your query:
MEMBER [Measures].[Test] AS {
StrToMember("[Time].[Date].&[" + [Project].[ParentProject].CURRENTMEMBER.PROPERTIES("Project Start Iso") + "]"):
StrToMember("[Time].[Date].&[" + [Project].[ParentProject].CURRENTMEMBER.PROPERTIES("Project End Iso") + "]")
}.COUNT

MDX multiple EXCEPT filter in calculated member

I have following query for calculated member:
SUM(
EXCEPT([Policy].[Policy Status].[Policy Status],[Policy].[Policy Status].&[Void])
, [Measures].[CountPolicyEndorsesNull]
)
What I want is to include another EXCLUDE filter. I have tried following:
SUM(
{EXCEPT([Policy].[Policy Status].[Policy Status],[Policy].[Policy Status].&[Void])}
*
{EXCEPT([Invoice].[Invoice Status].[Invoice Status],[Invoice].[Invoice Status].&[Void])}
, [Measures].[CountPolicyEndorsesNull]
)
but it returns more result than the first query. Any ideas?
Your syntax is correct. The reasons it could be more are the following:
You have negative results in ([Invoice].[Invoice Status].&[Void], [Measures].[CountPolicyEndorsesNull])
You have a default member set on [Invoice].[Invoice Status].[Invoice Status].
Try returning the following query:
select
[Measures].[CountPolicyEndorsesNull]
on columns,
{[Invoice].[Invoice Status].DefaultMember,
[Invoice].[Invoice Status].&[Void]
}
on rows
from [CubeName]
That will get you your culprit.