MDX queries test - mdx

I want to combine 3 queries like that in one query but I don't know how can I do this:
Query 1:
select {
Crossjoin({[Measures].[Store sales]}, {[Occupation].[Occupation].Members})
} on columns,
{
[Product].[Product Family].Members
} on rows
From test

Something like this is ok - but you need to bring All members into the script so that each set of tuples has the same dimensionality:
SELECT
[Measures].[Store sales]
*
{
[Occupation].[Occupation].MEMBERS * {[Essai].[All]}
,
{[Occupation].[All]} * [Essai].[Essai].MEMBERS
} ON COLUMNS
,{[Product].[Product Family].MEMBERS} ON ROWS
FROM test;

Sorry, the second query is
select {
Crossjoin({[Measures].[Store sales]}, {[Yearly_Income]. [Yearly_Income].Members})
} on columns,
{
[Product].[Product Family].Members
} on rows
From test

Related

MDX query - Subselect implementation - Select all values of a column except one

I have to implement a query with the following requirements.
1) I need to have multiple conditions(with AND,OR).
2) There are conditions where I need to exclude the records with a particular value.
SELECT {...} ON Columns, {...} ON ROWS
FROM
(SELECT {([Element1].[Value].&[98]&[002], [Element2].Value.&[Value1]),
([Element1].[Value].&[98]&[004], [Element2].Value.&[Value2]), ([Element1].[Value].&[98]&[005], [Element2].Value.NOTIN[value1, value2]), } ON Columns
FROM [CubeName])
I have mentioned NOTIN[value1,value2]) as I am unaware of how this can be implemented. I have to get all values except those mentioned. Please let me know if any one can provide a solution.
You would generally use the function EXCEPT to exclude some members from a set:
SELECT
{...} ON 0
, {...} ON 1
FROM
(
SELECT
EXCEPT(
[Element1].[Value].[Value].MEMBERS //<<name of the full set
,{ //<<the set to be excluded
[Element1].[Value].&[98]&[002],
[Element1].[Value].&[98]&[004],
[Element1].[Value].&[98]&[005]
} ON 0
FROM [CubeName]
);
The above could be expanded out to tuples but the first argument will need to be a cross-join:
SELECT
{...} ON 0
, {...} ON 1
FROM
(
SELECT
EXCEPT(
[Element1].[Hier1].[Hier1].MEMBERS
* [Element1].[Hier2].[Hier2].MEMBERS //<<name of the full set
,{ //<<the set to be excluded
([Element1].[Hier1].[Hier1].&[Value1],[Element1].[Hier2].[Hier2].&[Value1]),
([Element1].[Hier1].[Hier1].&[Value2],[Element1].[Hier2].[Hier2].&[Value2]),
([Element1].[Hier1].[Hier1].&[Value3],[Element1].[Hier2].[Hier2].&[Value3]),
} ON 0
FROM [CubeName]
);

MDX query optimization while using CrossJoin

I am writing an MDX query in which i am selecting some Measures and while selection i have a where condition in which i am doing a cross join two facts , one is date and another a unique id and i am passing around 2000 unique ids and the query is taking around 20 minutes to execute and give the result.
Please find below query for the same
SELECT {[Measures].[TOTAL1], [Measures].[TOTAL2], [Measures].[TOAL3]} ON COLUMNS,
" + " {TOPCOUNT(FILTER([ID].[Ids].MEMBERS,
[ID].CurrentMember > 0),
5,[Measures].[TOTAL])} " + "ON ROWS
FROM [CHARTS]
WHERE({[Date].&[2015-09-01 00:00:00.0]}*{[NUM].[1],[NUM].[10],"
+ "[NUM].[18],[NUM].[47],[NUM].[52],[NUM].[105],[NUM].[126],[NUM].[392],"
+ "[NUM].[588],[NUM].[656],[NUM].[995],[NUM].[1005],[NUM].[1010],[NUM].[1061]})";
The straight mdx without the string manipulation operators (+) is as follows:
SELECT
{
[Measures].[TOTAL1]
,[Measures].[TOTAL2]
,[Measures].[TOAL3]
} ON COLUMNS
,{
TopCount
(
Filter
(
[ID].[Ids].MEMBERS
,
[ID].CurrentMember > 0
)
,5
,[Measures].[TOTAL]
)
} ON ROWS
FROM [CHARTS]
WHERE
{[Date].&[2015-09-01 00:00:00.0]}
*
{
[NUM].[1]
,[NUM].[10]
,[NUM].[18]
,[NUM].[47]
,[NUM].[52]
,[NUM].[105]
,[NUM].[126]
,[NUM].[392]
,[NUM].[588]
,[NUM].[656]
,[NUM].[995]
,[NUM].[1005]
,[NUM].[1010]
,[NUM].[1061]
};
Can you please tell me the different performance optimization techniques for the same.
TopCount is slow if you use the third ordering parameter - it is better to order the data first and then feed your pre-ordered set into TopCount with just 2 parameters:
WITH
SET [S0] AS
Filter
(
[ID].[Ids].MEMBERS
,
[ID].CurrentMember > 0
)
SET [S1] AS
Order
(
[S0]
,[Measures].[TOTAL]
,BDESC
)
SET [S2] AS
TopCount
(
[S1]
,5
)
SELECT
{
[Measures].[TOTAL1]
,[Measures].[TOTAL2]
,[Measures].[TOAL3]
} ON COLUMNS
,[S2] ON ROWS
FROM [CHARTS]
WHERE
{[Date].&[2015-09-01 00:00:00.0]}
*
{
[NUM].[1]
,[NUM].[10]
,[NUM].[18]
,[NUM].[47]
,[NUM].[52]
,[NUM].[105]
,[NUM].[126]
,[NUM].[392]
,[NUM].[588]
,[NUM].[656]
,[NUM].[995]
,[NUM].[1005]
,[NUM].[1010]
,[NUM].[1061]
};

Can you help me to build my MDX query

This is my table :
I want is to display messageBySession, imageBySession and videoBySession in Columns and UserDimension with dateDimension in Row. Is this possible ?
Edit
Here is my attempt at the query :
SELECT
{
[Measures].[MessageBySession]
,[Measures].[ImageBySession]
,[Measures].[VideoBySession]
} ON COLUMNS
,Hierarchize(CrossJoin([DateDimension].Children,[UserDimension].Children)) ON ROWS
FROM [SessionFacts];
I just need to Join DateDimension with UserDimension. i hope it can help someone.
i found the query :
select {
[Measures].[MessageBySession],
[Measures].[ImageBySession],
[Measures].[VideoBySession]
} ON COLUMNS,
Hierarchize(
CrossJoin(
[DateDimension].children,
[UserDimension].children
)
)
ON ROWS
from
[SessionFacts]
I just need to Join DateDimension with UserDimension. i hope it can help someone.

Mondrian cache is used when it shouldn't

I have a problem with what it seems to be Mondrian's cache. I have this query:
SELECT
{ [Measures].[Searches] } ON COLUMNS,
{ [Date.Date].[2014].[4].[4] , [Date.Date].[2014].[4].[3] } ON ROWS
FROM [Searches]
that returns:
[Measures].[Searches]
[Date].[2014].[4].[4] 463
[Date].[2014].[4].[3] 381
what is correct. But if I do this query before the above one:
WITH
SET [TopCombinations] AS TOPCOUNT([Tags Group.Tag Group Combinations].[Combination].Members, 5000, [Measures].[Searches])
SELECT
{ [Measures].[Searches] } ON COLUMNS,
{ Filter( {[TopCombinations] }, [Measures].Searches > 5 ) } ON ROWS
FROM [Searches]
WHERE ( [Date.Date].[2014].[4].[4] )
when I do the first query, it returns a different result:
[Measures].[Searches]
[Date].[2014].[4].[4] 2,061
[Date].[2014].[4].[3] 381
It seems that when the Topcount query is done, some cache is made. After that the other query uses cached data and returns a different value. Any thoughts on what is going on here?
Thanks

How do I exclude columns which start with a specific string in MDX?

I'm trying to write an MDX query with the equivalent SQL:
SELECT m.ID, m.CID, m.Orders
FROM dbo.Measures as m
WHERE SUBSTRING(m.CID, 1, 4) <> 'PID_'
Essentially, exclude all rows where CID begins with 'PID_'
This is what I have in MDX so far:
SELECT
{
[Measures].[ID] AS ID,
[Measures].[Orders] AS NumberOfOrders,
}
ON COLUMNS,
{
[Channel].[Channel Account ID].[Channel Account ID].Members
* [Channel].[Channel].[Channel].Members // exclude accounts starting with 'PID_'
}
I've tried EXCEPT and - and WHERE clauses, but none seem to work.
Any help is appreciated!
I found the answer with the links xQbert provided.
This was the answer:
ON COLUMNS,
{
FILTER([Channel].[Channel Account ID].[Channel Account ID].Members,
LEFT([Channel].[Channel Account].Properties("Channel Account ID"), 4)
<> "PID_")
* [Channel].[Channel].[Channel].Members
}