MDX: How To Aggregate Hierarchy Level Members With Same Name - mdx

Greetings,
I am new to MDX, and am having trouble understanding how to perform an aggregation on a hierarchy level with members that have the same names. This query is particular to Microsoft Analysis Services 2000 cubes.
I have a given hierarchy dimension with levels defined as follows:
[Segment].[Flow].[Segment Week]
Within the [Segment Week] level, I have the following members:
[Week- 1]
[Week- 2]
[Week- 3]
...
[Week- 1]
[Week- 2]
[Week- 3]
The members have the same names, but are aligned with a different [Flow] in the parent level. So, the first occurrence of the [Week- 1] member aligns with [Flow].[A] while the second occurrence of [Week- 1] aligns with [Flow].[B]. What I am trying to do is aggregate all the members within the [Segment Week] level that have the same name. In SQL terms, I want to GROUP BY the member names within the [Segment Week] level. I am unsure how to do this. Thank you.
Dave

I think your cube design is flawed.
The best way to design a dimension is so all its members are unique, and the aggregation path follows the natural hierarchy of the dimension.
You could remove the WEEK level from SEGMENT and create another dimension (if I remember correctly, you can't have more than one hierarchy in AS 2000), say WEEK, with the following structure:
[Week].[Week- 1]
[Week].[Week- 2]
[Week].[Week- 3]
etc
Then you just have to filter by SEGMENT and by Week.
For example, to get all the Week1 of Flow A you'd do:
SELECT {[Measures].members} on 0
FROM MYCUBE
WHERE ([Week].[Week- 1],[Segment].[A])

Could you use the key of the member?
[Week].&[1] ([Week].[Week - 1] (flow1))
[Week].&[5] ([Week].[Week - 1] (flow2))
For reference, in the 'Adventure Works DW Standard Ed' Cube for 2008, the key for Customer Aaron A. Allen is [Customer].[Customer].&[20075]
UPDATE:
Sorry, just reread your question, it looks like you're not trying to get the specific week to a flow, you want to aggreagate them. What about a CASE Statement like this:
CASE
WHEN [Week].CURRENTMEMBER.NAME='Week - 1'
THEN [Week].CURRENTMEMBER
ELSE 0
END
Not very generic or flexible, but it might be a start...

Related

SSAS : Filter Cube

I have dimension and fact table. The dimension is PATIENTDBOID meanwhile the fact table is Total_Admissions.
Now, I want to filter for Patient that Admission >1
Can someone help me how. ?
You Can use Filter Function to Apply filter on Measures with Logical Expression.
Since I don't know Exact Dimension Name, You can try something like below.
0 - Represents COLUMNS
1 - Represents Rows
SELECT [Measures].[Total_Admissions] ON 0,
FILTER(
[Patient].[Patient].[PatientDBOID].MEMBERS
, [Measures].[Total_Admissions]>1)
ON 1
FROM [Cube Name]

Sum part of hierarchy based on second attribute from same dimension

so I have this dimension which has a ragged hierarchy. The hierarchy is nice to navigate but a royal pain to search in (Excel is the front end, so you have to search manually in all 12 or so levels).
We created a separate "search" attribute with all the members of the hierarchy to search in - however, in this flat list the leaves will contain the proper data but the intermediate nodes will of course not be rolled up (in lack of hierarchical information)
My idea was to put a formula on the flat list to go look up its equivalent member in the hierarchy and get its value from there.
Here's what I have - both approaches don't work unfortunately:
With
------ APPROACH 1: DESCENDANTS
Member [m1] As
Sum(
Descendants(
Filter(
[Dimension].[Hierarchy].Members
, [Dimension].[Hierarchy].Properties("Key") =
[Dimension].[Flat List].CurrentMember.Properties("Key")
),, LEAVES), ([Measure].[MeasureHierarchy].CurrentMember, [Measures].[Amount]))
------- APPROACH 2: StrToMember + CHILDREN
Member [m2] As
Sum(
StrToMember("[Dimension].[Hierarchy].&["+
[Dimension].[Flat List].CurrentMember.Properties("Key")+
"]").Children,
([Measure].[MeasureHierarchy].CurrentMember, [Measures].[Amount])
)
Select
{ [m1], [m2] }
On 0,
[Dimension].[Flat List].&[838]
dimension properties member_key
On 1
From [Cube]
Where [Measure].[MeasureHierarchy].[SomeMeasure]
Both will always return null - if I query the Hierarchy directly, it works - just not if I use the flat list
Any ideas?
figured it out myself - had a spark of inspiration tonight :-D
the answer is as simple as:
with member
[m1] as
(
StrToMember("[Dimension].[Hierarchy].&["+
[Dimension].[Flat List].CurrentMember.Properties("Key")+
"]")
, [Dimension].[Flat List].[All]
)
...
Maybe that will help someone else too

Persisting user-defined groupings of members in SSAS cube

I would like to allow users to specify their own dynamic grouping of members. In the AdventureWorks tutorial, that would mean a user could define "Product Group 1" as Accessories and Clothing, and "Product Group 2" as Accessories and Bikes." I could have an
I can get results like that by defining members as part of the MDX query:
with
member [Product].[Category].[Product Group 1] as
aggregate({[Product].[Category].[Accessories], [Product].[Category].[Clothing]})
member [Product].[Category].[Product Group 2] as
aggregate({[Product].[Category].[Accessories], [Product].[Category].[Bikes]})
select [Measures].[Internet Sales-Sales Amount] on 0,
{[Product].[Category].[Product Group 1], [Product].[Category].[Product Group 2] } on 1
from [Analysis Services Tutorial]
My question is: is there any way I could save these product groups as part of the cube, so you could just reference {[Product].[CustomGroups]} rather than having to include with member group1 as ... member group2 as .. on the query?
Sure, I could incorporate them into the dimensional model itself, which is almost what I want, but I'd like changes to take effect without refreshing the cube.
As mentioned in the comments. Inside the cube-script you should be able to:
1.
CREATE the custom members that you mentioned:
create member [product group 1] as ...
create member [product group 2] as ...
2.
CREATE the custom set that you mentioned:
create set [productSet] as ...{[product group 1],[product group 2]}
Exact syntax for the above will be on MSDN

Distinctly counting measure results that match a certain criteria

We have a measure for feedback scores which I am trying to report on. I need to calculate how many have reached a score >5 to calculate a performance %age. The issue I have is where there is more than one score available for my member which is aggregated in my results.
Here is what I have so far:
with
MEMBER [Client Sat Score] AS ([Measures].[Avg_Score], Linkmember([Bill Period].[Fiscal].[Fiscal Period].&[201409],[Date].[Fiscal]),[Bill Period].[Fiscal].[All],[Time Slice].[KeyTimeSlice].[12M])
MEMBER [Sum Scores] AS([Measures].[Sum of Scores], Linkmember([Bill Period].[Fiscal].[Fiscal Period].&[201409],[Date].[Fiscal]),[Bill Period].[Fiscal].[All],[Time Slice].[KeyTimeSlice].[12M])
MEMBER [Number Scores] AS([Measures].[Number of Scores], Linkmember([Bill Period].[Fiscal].[Fiscal Period].&[201409],[Date].[Fiscal]),[Bill Period].[Fiscal].[All],[Time Slice].[KeyTimeSlice].[12M])
MEMBER [Over 5] As IIF([Client Sat Score]>5,1,NULL)
MEMBER [Scores Over 5] As SUM([Matter].[KeyMatterNumber].[KeyMatterNumber].members,[Over 5])
MEMBER [Percent 6 or 7s] As IIF([Number Scores]=0,NULL,[Scores Over 5] / [Number Scores])
select {[Client Sat Score],[Sum Scores],[Number Scores],[Over 5],[Scores Over 5],[Percent 6 or 7s] }
on columns,
non empty ({[Client].[KeyClientRelatedID].&[XXX] })
on rows
from [Cube]
This returns 4 for "Scores over 5" but there are actually 2 scores of 7 on one of the members. These scores are on different date keys but I am unable to stop them aggregating within the SUM.
Any suggestions/advice please?
EDIT:
I've found that if I run the following I do get the 5 separate results each with a score above 5:
select {[Measures].[Avg_Score] }
on columns,
non empty ({[Matter].[KeyMatterNumber].[KeyMatterNumber].members })*
{[Date].[KeyDate].[KeyDate].&[20130206]:[Date].[KeyDate].[KeyDate].&[20140206]}
on rows
from [Cube]
where (
[Client].[KeyClientRelatedID].&[XXXX]
)
Does this help at all with the amendment of my first query?
It is difficult to answer without a cube schema available. However, it sounds like you are trying to do a row level calculation post-aggregation which results in your attempts to find the combination of dimensions that will cause leaf level data to be used in the calculation. Even if possible these invariably perform badly.
I would suggest pushing this calculation into the underlying database and generating an additional dimension with banded values { [1-5], [6-7] }.
Also, you didn't mention if this Analysis Services (or another vendor) Multidimensional or Tabular - if Tabular just create a row calc for "Over 5" in the cube and use that as your new dimension members.

How to create a calculated member based on two measures and the hierarchy level of the queried dimension's current member?

I have a cube which has
two measure members: [Measures].[Value] (integer) and [Measures].[EffectiveBelowLevel] (integer).
a dimension called [DimParentChild] with a ragged user hierarchy called [ParentChildHierarchy].
I would like to create a calculated member on the measures dimension ([Measures].[EffectiveValue]) based on [Measures].[Value] which when queried along [DimParentChild] and [ParentChildHierarchy] behaves as follows:
- [Measures].[Value] is used if the hierarchy level of [DimParentChild].[ParentChildHierarchy].CURRENTMEMBER > [Measures].[EffectiveBelowLevel].
- 0 is used if the hierarchy level of [DimParentChild].[ParentChildHierarchy].CURRENTMEMBER <= [Measures].[EffectiveBelowLevel].
Is it possible to achieve this functionaly with a calcuated member on the measures dimension?
If yes then what the formula would look like?
If not then what other way would there be?
I am very interested in any other kind of solution as well (e.g. an mdx query, etc.)
As an example:
[Measures]
[Value] [EffectiveBelowLevel] ParentChildAssociation
10 1 GrandChild1
20 2 GrandChild2
[DimParentChild].[ParentChildHierarchy]
Member HierarchyLevel Description
Parent 1 -
Child 2 first child of Parent
GrandChild1 3 first child of Child
GrandChild2 3 second child of Child
With this data [Measures].[EffectiveValue] should look like this
ParentChild EffectiveValue
Parent 0
Child 10
GrandChild1 10
GrandChild2 20
How about something along the lines (I'm not sure about level ordinal being 0-based):
with member xx as
Sum( [DimParentChild].[ParentChildHierarchy].currentMember as myCurrentMember,
Sum( Descendants( myCurrentMember(0), 64, LEAVES ),
IIF( myCurrentMember(0).level.ordinal > [EffectiveBelowLevel], [Value], 0 )
)
)
select [xx] on 0, [DimParentChild].[ParentChildHierarchy].members on 1 from [...]
You can have a look to this MDX documentation here for more details.
I see you have posted this question here also (saw it originally on ssas msdn forum), so I am providing the link to my answer as it might help other people. thread link on SSAS msdn forum
#Marc - As this is a case of parent child dimension and p/c dimensions can have data associated on nonleaf members your query would not return the correct results. It took me some time to figure out how to aggregate the correct results from children in this case and recommend you have a look at the link. Offtopic: good luck with your product, I hope I'll get the time to evaulate it one day :)
Regards,
Hrvoje