MDX Cross joins across user defined hierarchies - mdx

I have an MDX query like;
with
set [IcPiyasaCC] as
{
[DimCostCenterView].[CostCenterKey].&[S_EDT],
[DimCostCenterView].[CostCenterKey].&[S_END.MRG],
[DimCostCenterView].[CostCenterKey].&[S_GM_YRD],
[DimCostCenterView].[CostCenterKey].&[S_PER.RAF],
[DimCostCenterView].[CostCenterKey].&[S_ULUSAL],
[DimCostCenterView].[CostCenterKey].&[S_PAS_MARG]
}
member [DimCostCenterView].[CostCenterKey].[IcPiyasa] as
aggregate([IcPiyasaCC])
SELECT
NON EMPTY
{
[Measures].[Fiili_TutarTonaj]
} ON COLUMNS,
NON EMPTY
{
(
[DimCostCenterView].[CostCenterKey].[IcPiyasa]
--*[DimCostCenterView].[CostCenterKey].[CostCenterKey].ALLMEMBERS
)
}
ON ROWS
and I can get desired output like;
- Fiili_TutarTonaj
IcPiyasa 6
But when I try to cross join with [DimCostCenterView].[CostCenterKey].[CostCenterKey].ALLMEMBERS which is on same hierarchy, to get if any related "CostCenterKey"s , I get "CostCenterKey hierarchy is used more than once in the Crossjoin function." error message. How can I crossjoin them to get result like;
- - Fiili_TutarTonaj
IcPiyasa S_EDT 1
IcPiyasa S_END.MRG 2
IcPiyasa S_ULUSAL 3
Thanks.

You can host the new aggregated member in a different hierarchy. The cross-join will then be possible:
WITH
SET [IcPiyasaCC] AS
{
[DimCostCenterView].[CostCenterKey].&[S_EDT],
[DimCostCenterView].[CostCenterKey].&[S_END.MRG],
[DimCostCenterView].[CostCenterKey].&[S_GM_YRD],
[DimCostCenterView].[CostCenterKey].&[S_PER.RAF],
[DimCostCenterView].[CostCenterKey].&[S_ULUSAL],
[DimCostCenterView].[CostCenterKey].&[S_PAS_MARG]
}
MEMBER [Geography].[Geography].[All].[IcPiyasa] AS
AGGREGATE(
[IcPiyasaCC],
([Geography].[Geography].[All])
)
SELECT
NON EMPTY
[Measures].[Fiili_TutarTonaj] ON 0,
NON EMPTY
[Geography].[Geography].[All].[IcPiyasa]
*[DimCostCenterView].[CostCenterKey].[CostCenterKey].ALLMEMBERS
ON 1
...
...
Or this:
WITH
SET [IcPiyasaCC] AS
{
[DimCostCenterView].[CostCenterKey].&[S_EDT],
[DimCostCenterView].[CostCenterKey].&[S_END.MRG],
[DimCostCenterView].[CostCenterKey].&[S_GM_YRD],
[DimCostCenterView].[CostCenterKey].&[S_PER.RAF],
[DimCostCenterView].[CostCenterKey].&[S_ULUSAL],
[DimCostCenterView].[CostCenterKey].&[S_PAS_MARG]
}
MEMBER [Measures].[ForceName] AS 'IcPiyasaCC'
MEMBER [Geography].[Geography].[All].[IcPiyasa] AS
(
[Geography].[Geography].[All]
,[Measures].[ForceName]
)
SELECT
NON EMPTY
[Measures].[Fiili_TutarTonaj] ON 0,
NON EMPTY
[Geography].[Geography].[All].[IcPiyasa]
*[DimCostCenterView].[CostCenterKey].[CostCenterKey].ALLMEMBERS
ON 1

Related

MDX query to join two different dimension members

I have below select statement which I want to convert into cube members and calculate the sum.
SELECT NON EMPTY { [Measures].[volume] } ON COLUMNS, NON EMPTY { ([par_Account].[Account].[Account].ALLMEMBERS * [Product].[Hierarchy].[Local product var].ALLMEMBERS ) } ON ROWS FROM ( SELECT ( { [Product].[Hierarchy].[local product Group].&[-33554010354150679].&[-952789350662854159].&[8639428195894987853] } ) ON COLUMNS FROM ( SELECT ( { [Time].[Financial Period].&[-8540082585673218205] } ) ON COLUMNS FROM ( SELECT ( { [Market].[Market].&[-3381499019102906042] } ) ON COLUMNS FROM [cube]))) WHERE ( [Market].[Market].&[-3381499019102906042], [Time].[Financial Period].&[-8540082585673218205] )
Please help me with this.
I guess this is what you are looking for. However its always nice to explain what your problem is, or perhaps provide screenshot.
SELECT
NON EMPTY { [Measures].[volume] } ON COLUMNS,
NON EMPTY {
(
[Market].[Market].&[-3381499019102906042] *
[Time].[Financial Period].&[-8540082585673218205] *
{ [Product].[Hierarchy].[local product Group].&[-33554010354150679].&[-952789350662854159].&[8639428195894987853] } *
[par_Account].[Account].[Account].ALLMEMBERS *
[Product].[Hierarchy].[Local product var].ALLMEMBERS
)
} ON ROWS
from [cube]

MDX - multiple filters on different dimension with OR condition

I have a problem with MDX querying.
I have one measure WEIGHT and two dimensions DESTINATION and SOURCE with the same attributes: NAME and TYPE.
I want to return:
SUM of WEIGHT
where
DESTINATION.TYPE="A"
**OR**
SOURCE.TYPE="B"
**AND**
(DESTINATION.TYPE **<>** SOURCE.TYPE)
If try this:
SELECT NON EMPTY {
[Measures].[Weight]
}
ON COLUMNS,
NON EMPTY {
([Source].[Name].[Name].ALLMEMBERS * [Destination].[Name].[Name].ALLMEMBERS )
}
ON ROWS
FROM
( SELECT ( { [Source].[Type].&[A] } ) ON COLUMNS FROM ( SELECT ( { [Destination].[Type].&[B] } )
ON COLUMNS FROM [CUBE])) WHERE ( [Destination].[Type].&[B], [Source].[Type].&[A] )
But it doesn't work.
In SQL it look like
Select source.name, destination.name, sum(weight) from cube
where
(source.type = "A" or destination.type = "b")
and
(source.type <> destination.type)
group by source.name, destination.name, source.type, destination.type
Your From section is a bit messy. Try the following:
SELECT
NON EMPTY { [Measures].[Weight] } ON COLUMNS,
NON EMPTY { [Source].[Name].[Name].ALLMEMBERS * [Destination].[Name].[Name].ALLMEMBERS } ON ROWS
FROM [CUBE]
WHERE ( {[Destination].[Type].&[B]} * {[Source].[Type].[All]} + {[Destination].[Type].[All]} * {[Source].[Type].&[A]} )

MDX Get UserName Where UserID

Here is my MDX query below:
SELECT
{
[Measures].[Amt Exrate]
,[Measures].[Comm Exrate]
} ON COLUMNS
,NonEmpty([AccSetting].[User N].[User N] * [Cur Log].[Cur Log ID].Children) ON ROWS
FROM [report]
WHERE
[AccSetting].[Ag ID].&[113];
http://i.stack.imgur.com/0yDHg.png
UserID =113 is a hierarchies and a want to get the userN of it
I want to return exactly UserName of UserID =113 on Rows. but I'm not sure how to do it.
If you just want the name and nothing else then this should do it:
SELECT
{} ON COLUMNS
,[AccSetting].[User N].[User N] ON ROWS
FROM [report]
WHERE
[AccSetting].[Ag ID].&[113];
If you want to turn the name into a measure then something like the following, with a custom measure should help:
WITH
MEMBER [Measures].[userName] AS
[AccSetting].[User N].CurrentMember.Member_Caption
SELECT
{} ON 0
,{
[Measures].[userName]
,[Measures].[Amt Exrate]
,[Measures].[Comm Exrate]
} ON 1
FROM [report]
WHERE
[AccSetting].[Ag ID].&[113];
To return the columns you mentioned in comment this should work:
SELECT
NON EMPTY
{
[Measures].[Amt Exrate]
,[Measures].[Comm Exrate]
} ON COLUMNS
,NON EMPTY
[AccSetting].[User N].[User N].MEMBERS
* [Cur Log].[Cur Log ID].MEMBERS
ON ROWS
FROM [report]
WHERE
[AccSetting].[Ag ID].&[113];
EDIT
Answer in this article:
Get hierarchies valuesName mdx
Try having this way:
with dynamic set UserN as
NonEmpty(
[AccSetting].[User N].[User N].members * [Cur Log].[Cur Log ID].Children
,
[AccSetting].[Ag ID].currentmember
*
{
[Measures].[Amt Exrate],
[Measures].[Comm Exrate]
}
)
SELECT
{
[Measures].[Amt Exrate]
,[Measures].[Comm Exrate]
} ON COLUMNS
,UserN ON ROWS
FROM [report]
WHERE
[AccSetting].[Ag ID].&[113];

Get hierarchies valuesName mdx

I created a hierarchies like this photo below:
http://i.stack.imgur.com/ErOXQ.png
On MDX query
Select [AccSetting].[UserN].[UserN] ON 1
FROM [Olap_report]
Where [AccSetting].[AgID].[115]
This query return all UserN are children of AgID 115. but I want to return exactly UserN of AgID =115?
Think I understand now - the name is is a property of the member.
Create a custom measure that returns the property.
WITH
MEMBER [Measures].[NameColumn] AS
[AccSetting].[AgID].CURRENTMEMBER.Member_Name
MEMBER [Measures].[NameColumn2] AS
[AccSetting].[AgID].CURRENTMEMBER.Name
SELECT
{
[Measures].[NameColumn]
,[Measures].[NameColumn2]
} ON 0,
[AccSetting].[AgID].[115] ON 1
FROM [Olap_report]
Reference to msdn:
https://msdn.microsoft.com/en-us/library/ms145583.aspx
Edit
First check the member exists:
SELECT
{
[Measures].[<add measure here>],
[Measures].[<add measure here>]
} ON 0,
{
[AccSetting].[AgID].[115],
[AccSetting].[AgID].[113]
} ON 1
FROM [Olap_report]

How do you get the total rows in an MDX query to use for paging?

I am attempting to implement paging to large datasets in MDX (SSAS).
I have the following to retrieve paged data which works fine:
SELECT
{
[Measures].[Mesasure1],
[Measures].[Measure2]
} ON COLUMNS,
SUBSET
(
ORDER
(
{
(
[Item].[Category].ALLMEMBERS
)
}, NULL, BASC
), 10, 50 --10 = start index, 50 = returned roes
)
ON ROWS
FROM ( SELECT ( { [Time].[Date].&[2012-04-15T00:00:00]:[Time].[Date].&[2012-04-20T00:00:00] } ) ON COLUMNS
FROM [DataMartPerformance]
))
However I cannot for the life of me find anywhere on the internet that helps explain how to get the total rows available. Do I do it in a seperate query? If so how?
Or can I wrap it into this one query somehow?
Similar to how you'd do TSQL paging, you'll need to run another query to count the total elements. You may have to tinker with this depending on how you've done your original query, but I use something like:
WITH
MEMBER [Measures].[ElementCount] AS
{
NONEMPTY
(
{
[Item].[Category].ALLMEMBERS *
{ [Time].[Date].&[2012-04-15T00:00:00]:[Time].[Date].&[2012-04-20T00:00:00] }
},
{
[Measures].[Mesasure1],
[Measures].[Measure2]
}
)
}.COUNT
SELECT
{
[Measures].[ElementCount]
}
ON COLUMNS
FROM
[DataMartPerformance]
For filtering, you can do dimension filters by using an exists against your dimension attributes:
WITH
MEMBER [Measures].[ElementCount] AS
{
NONEMPTY
(
EXISTS
(
{
[Item].[Category].ALLMEMBERS *
{ [Time].[Date].&[2012-04-15T00:00:00]:[Time].[Date].&[2012-04-20T00:00:00] }
},
{
[Dimension].[Attribute].[FilterByThisAttribute]
}
),
{
[Measures].[Mesasure1],
[Measures].[Measure2]
}
)
}.COUNT
SELECT
{
[Measures].[ElementCount]
}
ON COLUMNS
FROM
[DataMartPerformance]
I haven't got to writing the measure value filters yet, I need to do that next for my own MDX paging constructor...
Please try this:
WITH
SET MySet As
(
NONEMPTY (
[AU Time Sale Hour].[Hour Key].[Hour Key]
* [Dim Country].[Country Key].[Country Key]
)
)
Member [Measures] .cnt AS MySet.Count
select [Measures] .cnt on Columns
from [Me Stats DW Fact Sales]
where (
{[Dim Visa].[Visa Key].&[2067],[Dim Visa].[Visa Key].&[2068] },
[AU Time Sale Date].[Date].&[20091120]:[AU Time Sale Date].[Date].&[20091125]
)