How to join two completely different cubes in MDX? - join

I want to join two completely different cubes in mdx (I am using MS SSRS 2008). I am really new to mdx and I have no idea how to do it. I want to join by SKU if possible. Can any body please tell me how to do it?
mdx Query 1
SELECT NON EMPTY { [Measures].[Sales], [Measures].[Quantity] } ON COLUMNS,
NON EMPTY { ([Date YMD].[Day].ALLMEMBERS *
[Regions And Stores].[Store Name].[Store Name].ALLMEMBERS *
[Products].[Products].ALLMEMBERS *
[SKU].[SKU].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM [Super] CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
mdx Query 2
SELECT NON EMPTY { [Measures].[Quantity] } ON COLUMNS,
NON EMPTY { ([Store Name].[Store Name].ALLMEMBERS *
[Products].[Products].ALLMEMBERS *
[SKU].[SKU].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM [Inventory Activity] CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
Any help will highly appreciated.
Thank you

In SSRS you need to load two Datasets in your report and join them in the tablix. For example:
Load Dataset1 and Dataset2 into your report, with the column ID which links Dataset1 to Dataset2. Then put a tablix in your report. Display Dataset1 in your tablix. Now add a new column to your tablix and add the following expression:
=Lookup(Fields!Dataset1ID.Value, Fields!Dataset2ID.Value, Fields!SalesAmount.Value, "Dataset2")
The expression works as follows:
- First argument is the foreign key column from Dataset1
Second argument is corrspondending key column from Dataset2
Third argument is the column you want to display in the tablix which is from Dataset2
Forth argument is the name from the dataset you want to join with (Dataset2)
Here is the reference for the Lookup() function: https://docs.microsoft.com/de-de/sql/reporting-services/report-design/report-builder-functions-lookup-function?view=sql-server-2017

Welcome to MDX, I guess you are looking for SQL Join equivalent in MDX. However MDX doesnt support joins like SQL. One way to solve the issue is to retrieve the data via ADOMD into data cells and then join them in memory. However I would like to know the scenario, which requires you to join results from two cubes.

Related

Using WITH in mdx to retrieve row names

I am executing the following MDX query in SSMS, which I have got from Profiler:
SELECT {
[Measures].[Dollar Amount],
[Measures].[Transaction Count]}
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON COLUMNS,
NON EMPTY Hierarchize({DrilldownLevel({[Retail Sales Date].[Month].[All]},,,INCLUDE_CALC_MEMBERS)})
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON ROWS
FROM [Retail Sales Cube]
WHERE ([Geography].[Retail Sales Location].[Country Name].&[Australia],[Retail Category].[Retail Category].[All])
CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS
This produces the following results (snippet only):
The rows are months, and because of the method of retrieval, I need the months to also be displayed in a column.
So I tried this:
WITH
MEMBER [TheDate] AS [Retail Sales Date].[Month].CurrentMember.Name
SELECT {
[TheDate],
[Measures].[Dollar Amount],
[Measures].[Transaction Count]}
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON COLUMNS,
NON EMPTY Hierarchize({DrilldownLevel({[Retail Sales Date].[Month].[All]},,,INCLUDE_CALC_MEMBERS)})
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON ROWS
FROM [Retail Sales Cube]
WHERE ([Geography].[Retail Sales Location].[Country Name].&[Australia],[Retail Category].[Retail Category].[All])
CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS
which would be fine, except that it also shows rows where there are null values, as follows:
I know there is NONEMPTY, but I don't know where I would put it. How can I get rid of the empty rows?
Perhaps the following expression would do the trick:
WITH
MEMBER [TheDate] AS
IIF( !isEmpty( [Dollar Amount] )
[Retail Sales Date].[Month].CurrentMember.Name,
null
)

Column names when cross joining in MDX

I am applying a crossjoin to get the columns from MDX:
SELECT { [Measures].[Balance] } ON 0,
NonEmpty ( {[Sources].[Sources].children*[AccountType].[Description].children}) ON 1
This however gives me the following:
|____|___________| Balance |
| XY | something | 12335435|
The result in its self is correct, but I need to name the two first columns so I can use the data in an RS report. How can I do this?
Not too sure what the problem is here.
Just paste your MDX into the Dataset in SSRS
Add a matrix to your report.
Select some of the available fields from the dataset for the report.
Rename columns in your matrix
Edit
I just copied this into my dataset and all columns appeared:
SELECT
NON EMPTY
{[Measures].[Internet Order Count]} ON COLUMNS
,NON EMPTY
{[Product].[Product Categories].[Category].ALLMEMBERS}
DIMENSION PROPERTIES
MEMBER_CAPTION
,MEMBER_UNIQUE_NAME
ON ROWS
FROM [Adventure Works]
Also when I use the wizard to build the query all columns appear ok

MDX: how to get dimension values as columns

firstly i apologize because i'm most certainly using the wrong terms here. My problem is that i have the query below that contains a dimension that has always two values (MONTH VALIDATION) as shown on the query and image below:
SELECT NON EMPTY {
[Measures].[00 - Costs €]
}
ON COLUMNS, NON EMPTY {(
[Project Platoon].[Platoon].[Platoon].ALLMEMBERS ,
[Financial Data Month Validation].[Month Validation Status].[Month Validation Status].ALLMEMBERS
)}
DIMENSION PROPERTIES
MEMBER_CAPTION,MEMBER_UNIQUE_NAME ON ROWS
FROM
[DataCube]
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
and i get a result like the one below:
My question is: how can i "flatify" this so that i show
|Platoon|Open |Closed|Costs|
|Borg...|12.000|99.000|12+99=111|
that is, transform the values of [MonthValidation] into columns ?
Just put the Month Validation Status hierarchy on the columns (that is why there is ON COLUMNS and ON ROWS):
SELECT NON EMPTY {
[Measures].[00 - Costs €]
} *
[Financial Data Month Validation].[Month Validation Status].[Month Validation Status].ALLMEMBERS
ON COLUMNS,
NON EMPTY {
[Project Platoon].[Platoon].[Platoon].ALLMEMBERS
}
DIMENSION PROPERTIES
MEMBER_CAPTION,MEMBER_UNIQUE_NAME ON ROWS
FROM
[DataCube]
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS

How to indicate the measure when use dimension members as ROWS in mdx query?

Here is the query that I am using:
SELECT
NON EMPTY { [Dim Date].[Week].[Week].Members } ON COLUMNS,
[Dim Source].[Source Name].[Source Name].Members ON ROWS
FROM [Some Cube];
The things is, right now, I have many measures.
But as I am using dimension members on COLUMNS, I cannot indicate the measure anymore.
So this query results in a default measure.
My question is how can I indicate the measure instead of using the default in mdx query?
Or is there any other way that I can do this query (dimension in both row and columns is required for reading result logic in C# in possible) ?
You can do it in two ways:
Either on the SELECT statement, as
{ [Dim Date].[Week].[Week].Members } * { [Measures].[My Measure] } ON COLUMNS,
or on the WHERE slicer by adding
WHERE [Measures].[My Measure]
at the end.

MDX Query Optimization

I have a pivot table generated in Excel. I need to use the same MDX query which is used in Excel, I have extracted the same query from Excel which is like this -
SELECT {[Measures].[OQ],[Measures].[RQ],[Measures].[SQ],[Measures].[SRQ]}
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON COLUMNS ,
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
Hierarchize({DrilldownLevel({[PO].[Date].[All]},,,INCLUDE_CALC_MEMBERS)}),
Hierarchize({DrilldownLevel({[PO].[Priority].[All]},,,INCLUDE_CALC_MEMBERS)})),
Hierarchize({DrilldownLevel({[POL].[Container].[All]},,,INCLUDE_CALC_MEMBERS)})),
Hierarchize({DrilldownLevel({[PO].[Name].[All]},,,INCLUDE_CALC_MEMBERS)})),
Hierarchize({DrilldownLevel({[POL].[Num].[All]},,,INCLUDE_CALC_MEMBERS)})),
Hierarchize({DrilldownLevel({[PO].[Warehouse].[All]},,,INCLUDE_CALC_MEMBERS)})),
Hierarchize({DrilldownLevel({[POL].[Status].[All]},,,INCLUDE_CALC_MEMBERS)})),
Hierarchize({DrilldownLevel({[POL].[Factor].[All]},,,INCLUDE_CALC_MEMBERS)}))
ON ROWS
FROM [Purchases] CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS
This query returns about 3 lac records in excel, when I run this query in SSMS it gives error like "Server: The operation has been cancelled due to memory pressure.".
I am new to MDX, above query uses many CrossJoins, is there any way to optimize this query?
Thanks and Regards,
Amit Thakkar
I think its result maybe unusable almost for statistic reason
because of returning many rows.
but for optimization I suggest using
NONEMPTY
front of your crossjoin

Resources