MDX Query Join Two Dimensions - sql

I have an MDX query as follows:
WITH
MEMBER [MatCode] AS [Product].[Material]
SELECT
([MatCode]) on 0,
([Activity].[ActivityCode].[T-50051151]) ON 1
FROM
[Cube]
This returns a value such as:
MatCode
T-50051151 Null
Which tells me it is not joining the activity code to the description when I know they match up
How can I correct my MDX query to join activity code to material?
thanks

Why not try something like the following to look for areas of the cube with data? You'll can use the WHERE clause to slice by a specific measure in your cube.
SELECT
{[Activity].[ActivityCode].[T-50051151]} ON 0,
//NON EMPTY //<<include to hide nulls
{[Product].[Material].members} on 1
FROM
[Cube]
WHERE
([Measures].[someMeasure])

Your query returns the _ default _ value / cell for the tuple :
( [Activity].[ActivityCode].[T-50051151], [Product].[Material].defaultMember )
as well as the .defaultMember for every other dimension not mentionned in your query. There is nothing wrong with it.

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]

How do I get .AllMembers of Hierarchy in olap4j?

I have an MDX query like this:
SELECT {[Gender].[Gender].AllMembers} ON COLUMNS,
{[Geography].[Country].AllMembers} ON ROWS FROM [myCube]
And I am trying to get this query as an olap4j object. I do this to set my dimension:
QueryDimension genderDim = myQuery.getDimension("GENDER");
But that produces just one column of "All Genders" and "All Geographys" respectively.
How do I get them broken down like the MDX query above?
If you switch to the MEMBERS function does that help?
SELECT
{[Gender].[Gender].MEMBERS} ON COLUMNS,
{[Geography].[Country].MEMBERS} ON ROWS
FROM [myCube];

MDX - Why Cross join between measures do not work?

In MDX, we can CROSS JOIN two members, a measure and a member but not two measures. Why is this so? What does it imply?
SELECT
[Measures].[xyz] * [DimTable1].[SomeHierarchy].[Level] on 0,
[DimTable2].[SomeOtherHierarchy].&[Value] on 1
FROM [MyCube]
// WORKS
SELECT
[Measures].[xyz] on 0,
[DimTable2].[SomeOtherHierarchy].&[Value] * [DimTable1].[SomeHierarchy].[Level] on 1
FROM [MyCube]
// OF COURSE IT WORKS
SELECT
[Measures].[xyz] * [Measures].[ABC] on 0,
[DimTable1].[SomeHierarchy].&[Value] on 1
FROM [MyCube]
// DOES NOT WORK!!
I believe you forgot:
SELECT
[dd].[hh].[mm1] * [dd].[hh].[mm2] on 0,
[DimTable1].[SomeHierarchy].&[Value] on 1 FROM [MyCube]
did not work neither. [Measures] is not different than [dd] in my example. In MDX you cannot define a tuple with _ several members _ of the _ same hierarchy _. Have a look to this gentle introduction explaining the main concepts.
EDIT
Your third query, that does not work, looks like this:
The yellow area is empty so it is understandable that it is not happy.
EDIT
Following is an analogy using Excel pivot tables which use OLAP technology
If you put a crossjoin of measures A and B on rows you get something like this:
Then if we add a very small level (with 4 members) onto columns we get the following:
So what will go into the main body of this table?
A count is possible and probably is, in MDX, if you create a custom measure (don't have a server to test this statement on). Excel will default to a count but the result is pretty pointless?

MDX query: filter and sum of filtered

I've just started to learn MDX and i want to do a query like that:
filter data by the cost ( i've already made that query but without the sum) like that:
SELECT [Measures].[SumOfSelled] ON 0,
FILTER ([From].[From].[City].members, [Measures].[SumOfSelled]>7000) ON 1
FROM [BI-Avia]
It's working
and it is OK
BUT!!!
I need also to show the sum of filtered elements under this filtered result by cities
I know how to find it separately:
with member [Measures].FilteredSum as sum(filter([From].From].City].members,Measures].SunOfSelled]>7000),Measures].[SumOfSelled])
select{SumOfSelled} on 0
from [BI-AVIA]
But i have to show this together!! The SUM under Filtered! two in one! I need youe help! I think it's very clear for you!!!
Just define the calculated member on the [From].[From] hierarchy and then combine both queries, using a union of sets (abbreviated with + in MDX):
with member [From].[From].FilteredSum as
sum(filter([From].[From].City].members, Measures].SumOfSelled]>7000))
SELECT [Measures].[SumOfSelled]
ON 0,
FILTER ([From].[From].[City].members, [Measures].[SumOfSelled]>7000)
+
{ [From].[From].FilteredSum }
ON 1
FROM [BI-Avia]
You could possibly define the filter as a set in the WITH clause, which would avoid that Analysis Services evaluates it twice.

Filtering dimensions in MDX inside a SUM

I am new to MDX expressions and I am trying to create one that sums the value of a given measure filtered by dimensions.
In my database I have several different dimensions that have the same name: "Answer". To sum them up, I have created the query below:
WITH MEMBER Measures.Total as SUM ({[Activity].[Activity].&[14], [Activity][Activity].&[22]},
[Measures].[Activity time])
SELECT NON EMPTY [Measures].[Total] on COLUMNS from [My Analytics]
This query works, however I had to use the "&[14]" and "&[22]" statments that correspond to two different "Answer" dimensions.
Since I have more than two dimensions with the same name, is there a way to rewrite the query above in a way that I would select all these dimensions without having to add their unique ID? For example, I would re-write the query as something like this:
WITH MEMBER Measures.Total as SUM ({[Activity].[Activity].&["Answer"]},
[Measures].[Activity time])
SELECT NON EMPTY [Measures].[Total] on COLUMNS from [My Analytics]
Is this possible?
Thanks!
You can use the Filter function as following:
with
set [my-answers] as
Filter( [Activity].[Activity].members,
[Activity].[Activity].currentMember.name = 'Answer'
)
member [Measures].[Total] as Sum( [my-answers] )
...