Showing posts with label structure. Show all posts
Showing posts with label structure. Show all posts

Monday, March 12, 2012

MDX to consolidate dates with measures by columns

I have a cube in SQL Server Analysis Services 2005 that has a structure like:

Measures:
Number of Tickets ([Measures].[Number of Tickets])

Dimensions:
Submitted Date ([Submit Date].[Date].[Date])
Submitted By ([Submit By].[Name].[Name])
Assigned Date ([Assigned Date].[Date].[Date])
Assigned To ([Assign To].[Name].[Name])
Resolved Date ([Resolved Date].[Date].[Date])
Resolved By ([Resolved By].[Name].[Name])
....
I would like to have returned a result set that cosolidates the dates with the number of tickets for each (or similarly, consolidates the people with the number of tickets for each). I need a set of all dates back, with the number of tickets aliased appropriately, so that I end up with something similar to the following:

Date # Tickets Submitted # Tickets Assigned # Tickets Resolved
April 1, 2007 14 27 11

April 2, 2007 11 4 null

April 3, 2007 null null 5
... etc.

What is the MDX to do this? I know how I would do it in t-sql, but unfortunately I'm not very proficient in mdx yet. I have tried using LinkMember and can get a single set of dates, but still don't know how to get the different ticket counts for each.

You might be able to figure something out with LinkMember, but it could get messy.

Have you considered changing your structure and setting up a couple of common dimensions instead? This should make a lot of different analysis a lot easier.

Measures:

SubmittedCount, AssignedCount, ResovledCount

Dimensions:

Date

Person

Or even something like

Measures:

ActivityCount

Dimensions:

Date

Person

Activity (Submitted, Resolved, Assigned)

|||

Hi Patty,

as Darren said one possibility is to change the structure of your measuregroup. If you are not able to do so you could try the following (SLOWER!!!) MDX.

If you use the same Date Dimension for all your Dates (-> Same Keys) you can use Filter or VBA to calculate your measures. I tried this in Adventureworks and for me the VBA was faster.

Here The MDX I used in Adventure Works DW:

Code Snippet

WITH MEMBER Measures.[Orders Delivered]

--AS ([Measures].[Order Count], ROOT([Date]), FILTER([Delivery Date].[Date].[Date].MEMBERS, [Delivery Date].[Date].MEMBER_KEY = [Date].[Date].CURRENTMEMBER.MEMBER_KEY).Item(0))

AS ([Measures].[Order Count], ROOT([Date]), StrToMember(VBA!CSTR("[Delivery Date].[Date].&[" + [Date].[Date].CURRENTMEMBER.MEMBER_KEY +"]")))

SELECT

{[Measures].[Order Count],Measures.[Orders Delivered] } ON COLUMNS,

{[Date].[Date].[Date].MEMBERS} ON ROWS

FROM [Adventure Works]

As u see I use the Key Of the Current Date to generate the UNIQUE_NAME in the other date dimension with vba. You should be able to replace Date with Submitted Date and Delivery Date with Assigned Date.

Hope this helps

Markus

Monday, February 20, 2012

MDX Parameter in Report...

Dear Friends,

I have a doubt, and I need your support...

I have 4 tables that are in one dimension STRUCTURE.

The Structure is:

1. Entidade

2. Carteira

3 Mesa

4. Folder

In my report I have these 4 combobox with data and related...

So the problem is...

I need to show a field in the report based on the selection... For example:

1oWhen

1. Entidade = 'LIS'

2. Carteira = 'ALL'

3 Mesa = 'ALL'

4. Folder = 'ALL'

I want to show in the textbox1.value the CalculatedMember1

2oWhen

1. Entidade = 'LIS'

2. Carteira = 'LIS-CPR'

3 Mesa = 'ALL'

4. Folder = 'ALL'

I want to show in the textbox1.value the CalculatedMember2

3oWhen

1. Entidade = 'LIS'

2. Carteira = 'LIS-CPR'

3 Mesa = 'LIS-CPR-ME1'

4. Folder = 'ALL'

I want to show in the textbox1.value the CalculatedMember3

4oWhen

1. Entidade = 'LIS'

2. Carteira = 'LIS-CPR'

3 Mesa = 'LIS-CPR-ME1'

4. Folder = 'FOLDER1'

I want to show in the textbox1.value the CalculatedMember4

It's Possible?

Someone help me?

Regards!!

I'm assuming that this means that you want the calculation to work differently at the different levels. Why not create a 4th calculation and use scope assignment to return the approriate value at the appropriate level?

I'm assuming that these attributes are in a hierarchy, but you did not mention what the name of that was, so I have just used the text "" as a placeholder.

Code Snippet

CREATE MEMBER currentcube.measures.CalculatedMember5 as (CalculatedMember1)

SCOPE (STRUCTURE.<hierarchy>.Carteira.Members);

(measures.CalculatedMember4) = (measures.CalculatedMember2);

END SCOPE;

SCOPE (STRUCTURE.<hierarchy>.Mesa.Members);

(measures.CalculatedMember4) = (measures.CalculatedMember3);

END SCOPE;

SCOPE (STRUCTURE.<hierarchy>.Folder.Members);

(measures.CalculatedMember4) = (measures.CalculatedMember4);

END SCOPE;

Then in your report you just referece CalculatedMember5

|||

Dear Darren,

I didn't understand your statment...

I need to use CM1 or CM2 or CM3 or CM4 depending on the values selected by the user in the combobox's report.

So I found a solution to get if inside the report, but It would be better If I control it in a CM in spite of textbox report... So I did like this:

Code Snippet

=IIF(Parameters!DimStructureCarteiraID.Value(0)="[DimStructure].[Carteira_ID].[All]"
AND Parameters!DimStructureMesaID.Value(0)="[DimStructure].[Mesa_ID].[All]"
AND Parameters!DimStructureFolderID.Value(0)="[DimStructure].[Folder_ID].[All]"
,Sum(Fields!CM_1.Value, "dSource1")
,IIF(Parameters!DimStructureMesaID.Value(0)="[DimStructure].[Mesa_ID].[All]"
AND Parameters!DimStructureFolderID.Value(0)="[DimStructure].[Folder_ID].[All]"
,Sum(Fields!CM_2.Value, "dSource1")
,IIF(Parameters!DimStructureFolderID.Value(0)="[DimStructure].[Folder_ID].[All]"
,Sum(Fields!CM_3.Value, "dSource1")
,Sum(Fields!CM_4.Value, "dSource1")
)
)
)

But would be better to call for example a CMX in spite of using this formula for each textbox...

I will try to convert this statment to inside my dataset...

Understood?

Regards and thanks!

|||The scope statement will only work inside the MDX script of your cube. You could probably do similar logic to your SSRS expression inside the MDX using a similar IIF() pattern.