MDX Combine two queries - ssas

I need two join two queries, I tried with members but it didn't work. I am new to MDX, please let me know if there a way of doing this. Error is due to list in the calculated member.
SELECT NON EMPTY { [RR TYPE].[Item].[Item].ALLMEMBERS * [Measures].[Unit Value] } ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS) } ON ROWS
FROM [GLCube]
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010]
,-{ [Ledger].[ID].&[A1],[Ledger].[ID].&[A2] ,[Ledger].[ID].&[A3]} )
SELECT NON EMPTY { [RT TYPE].[Item].[Item].ALLMEMBERS * [Measures].[Price Value] } ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS) } ON ROWS
FROM (SELECT [CCTYPE].[Desc].&[FCD] ON COLUMNS
FROM [GLCube])
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010])
Combined query
WITH MEMBER [Measures].[Unit Value]] AS
(-{[Ledger].[ID].&[A1],[Ledger].[ID].&[A2] ,[Ledger].[ID].&[A3]},[Measures].[Unit Value])
MEMBER [Measures].[Price Value] AS
( [CCTYPE].[Desc].&[FCD],[Measures].[Price Value] )
SELECT NON EMPTY {[Measures].[Unit Value],[Measures].[Price Value]} ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS} ON ROWS
FROM [GLCube]
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010])
Expected Output

WITH
MEMBER [Measures].[Filtered Unit Value] as
Aggregate(
-{ [Ledger].[ID].&[A1],[Ledger].[ID].&[A2] ,[Ledger].[ID].&[A3]},
[Measures].[Unit Value]
)
SELECT NON EMPTY
{
[RR TYPE].[Item].[Item].ALLMEMBERS
* {[RT TYPE].[Item].[All]}
* { [CCTYPE].[Desc].[All]}
* [Measures].[Filtered Unit Value]
}
+
{
{[RR TYPE].[Item].[All]}
* [RT TYPE].[Item].[Item].ALLMEMBERS
* { [CCTYPE].[Desc].&[FCD]}
* [Measures].[Price Value]
}
ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS) } ON ROWS
FROM [GLCube]
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010]
)

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]} )

OrderBy MDX Queries?

This is my MDX Query.
select
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
on columns,
NON EMPTY
{(
[Products].[Item Description].children,
[Calendar].[Date].[Date]
)}
on rows
from
(
select
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON columns
FROM [SalesReport])
This gives the sales records in quantity and net sales as expected. We need now to sort it to get the item which has the highest quantity in first. In other words, we're looking to apply 'descending' sort here.
I tried all order method which gives me error. Can you please help me to get my wish done?
Have you tried the below ?
select
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
on columns,
NON EMPTY
ORDER((
[Products].[Item Description].children,
[Calendar].[Date].[Date]
), [Measures].[Quantity], DESC)
on rows
from
(
select
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON columns
FROM [SalesReport])
Second attempt [WORKING SOLUTION]
select
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
on columns,
NON EMPTY
ORDER((
[Products].[Item Description].children
), [Measures].[Quantity], DESC)
*[Calendar].[Date].[Date]
on rows
from
(
select
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON columns
FROM [SalesReport])
If you wanted to further order the inner group you could do this:
SELECT
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
ON 0,
NON EMPTY
GENERATE(
ORDER(
[Products].[Item Description].children
,[Measures].[Quantity], BDESC)
,
ORDER(
[Products].[Item Description].CURRENTMEMBER //<< possibly [Products].CURRENTMEMBER
*
{[Calendar].[Date].[Date].Members}
,[Measures].[Quantity], BDESC))
ON 1
FROM
(
SELECT
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON 0
FROM [SalesReport]
);

How to get top 5 in mdx

How to get top 5 from mdx query?
I have a this query:
WITH SET [Geography].[City] AS
TopCount(
[Geography].[City]
,5
,[Measures].[Reseller Freight Cost]
)
SELECT
NON EMPTY {
CROSSJOIN(
{
[Date].[Calendar]
},
{
[Product].[Category]
}
),
CROSSJOIN(
{
[Date].[Calendar].children
},
{
[Product].[Category]
}
)
} DIMENSION PROPERTIES children_cardinality, parent_unique_name ON COLUMNS,
NON EMPTY {
[Geography].[City],
[Geography].[City].children
} DIMENSION PROPERTIES children_cardinality, parent_unique_name ON ROWS
FROM [Adventure Works]
WHERE (
[Measures].[Reseller Freight Cost]
)
But is not working.
Now i have error
error: {"faultstring":"Query (1, 21) Parser: The syntax for '.' is incorrect.","faultcode":"XMLAnalysisError.0xc10e0002"}
The best if I not must change a code after SELECT word .
When you create a set just declare it with no associated hierarchy so this is wrong [Geography].[City].
Also there is a much more readable syntax for cross-join - just use an asterisk *
Try this:
WITH SET [CitySet] AS
TopCount(
[Geography].[City]
,5
,[Measures].[Reseller Freight Cost]
)
SELECT
NON EMPTY {
[Date].[Calendar] * [Product].[Category]
,[Date].[Calendar].children * [Product].[Category]
} DIMENSION PROPERTIES children_cardinality, parent_unique_name ON COLUMNS,
NON EMPTY {
[CitySet], //<<changed here [Geography].[City],
[Geography].[City].children
}
DIMENSION PROPERTIES children_cardinality, parent_unique_name ON ROWS
FROM [Adventure Works]
WHERE (
[Measures].[Reseller Freight Cost]
)

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]
)