I use SQL Server 2008 R2 and i use SSRS and i use Adventure Work DataBase.
I write this MDX query for get 10 city that were in top ten in both years 2003 , 2004.
with
set [Best Cities in CY 2003/2004] as
intersect(
order(
topcount(
[Customer].[Customer Geography].[City],
10,
(
[Measures].[Internet Sales Amount],
[Date].[Calendar].[Calendar Year].[CY 2003]
)
),
[Measures].[Internet Sales Amount],
bdesc
),
order(
topcount(
[Customer].[Customer Geography].[City],
10,
(
[Measures].[Internet Sales Amount],
[Date].[Calendar].[Calendar Year].[CY 2004]
)
),
[Measures].[Internet Sales Amount],
bdesc
)
)
Select [Measures].[Internet Sales Amount] on columns,
[Best Cities in CY 2003/2004] on rows
From [Adventure Works]
Where
{
[Date].[Calendar].[Calendar Year].[CY 2003],
[Date].[Calendar].[Calendar Year].[CY 2004]
}
But i want get list of cities that internet sales has decreased by 35% compared to the previous year and cities among the top 10 cities in the same year as well.
How i can get this result?
You would use Filter for this:
with
set [Best Cities in CY 2003/2004] as
filter(
intersect(
topcount(
[Customer].[Customer Geography].[City],
10,
(
[Measures].[Internet Sales Amount],
[Date].[Calendar].[Calendar Year].[CY 2003]
)
),
topcount(
[Customer].[Customer Geography].[City],
10,
(
[Measures].[Internet Sales Amount],
[Date].[Calendar].[Calendar Year].[CY 2004]
)
)
),
([Measures].[Internet Sales Amount], [Date].[Calendar].[Calendar Year].[CY 2004])
/
([Measures].[Internet Sales Amount], [Date].[Calendar].[Calendar Year].[CY 2003])
- 1.0
< -0.35
)
Select [Measures].[Internet Sales Amount] on columns,
[Best Cities in CY 2003/2004] on rows
From [Adventure Works]
Where
{
[Date].[Calendar].[Calendar Year].[CY 2003],
[Date].[Calendar].[Calendar Year].[CY 2004]
}
Related
I need to order Dimension with respect to descending order. without using HIERARCHIZE key word everything works fine. here i need HIERARCHIZE in order to order hierarchy level data.
Select NON EMPTY({[Measures].[Internet Sales Amount]}) dimension properties MEMBER_TYPE,CHILDREN_CARDINALITY, PARENT_UNIQUE_NAME ON COLUMNS ,NON EMPTY(HIERARCHIZE({{ORDER(drilldownlevel([Customer].[Customer Geography]),[Customer].[Customer Geography].CurrentMember.MEMBER_CAPTION,desc)}})) dimension properties MEMBER_TYPE,CHILDREN_CARDINALITY, PARENT_UNIQUE_NAME ON ROWS
Unfortunely I do not have AdvWrks cube to test the following:
SELECT
NON EMPTY
[Measures].[Internet Sales Amount] ON 0
,NON EMPTY
ORDER(
{
HIERARCHIZE([Customer].[Customer Geography].[COUNTRY].MEMBERS)
,[Customer].[Customer Geography].[COUNTRY].&[GERMANY].CHILDREN
}
,[Customer].[Customer Geography].CurrentMember.MEMBER_CAPTION
,BDESC
)
) ON 1
FROM [Adventure Works];
Looks like I had a tested solution to a similar problem here:
Issue with Order function and Crossoins in MDX
Looks like an application of the above to your context is something like this:
SELECT
NON EMPTY
[Measures].[Internet Sales Amount] ON 0
,NON EMPTY
{
Order
(
{
[Customer].[Customer Geography].[COUNTRY].MEMBERS
, [Customer].[Customer Geography].[COUNTRY].&[GERMANY].CHILDREN
}
,(
[Measures].[Internet Sales Amount]
,[Customer].[Customer Geography].[COUNTRY]
)
,BDESC
)
} ON 1
FROM [Adventure Works];
Resolved the issues with below query
SELECT
NON EMPTY [Measures].[Internet Sales Amount] ON 0,
NON EMPTY
Order(
Hierarchize(
[Customer].[Customer Geography].[Country].&[Germany].Children
)
,[Customer].[Customer Geography].CurrentMember.MEMBER_CAPTION
,DESC
)
ON 1
FROM [Adventure works];
Using AdventureWorksDW2008R I have the following DataSet
SELECT NON EMPTY {
[Measures].[Sales Amount], [Measures].[Total Product Cost], [Measures].[Internet Sales Count]
} ON COLUMNS, NON EMPTY
{
([Order Date].[Calendar Year].[Calendar Year].ALLMEMBERS )
} DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM [Adventure Works Cube]
Resutls are:
Sales Amount Total Product Cost Internet Sales Count
2005 4342674.0296 2562584.6235 8949
2008 25016003.1911002 14715208.9522001 51449
Is there a way to calculate the variance of each in the report?
For example the Variance of Internet Sales Count would be:
51449 – 8949 = 42500
And the % variance would be
42500/51449 = 83%
I know I can use the following to get the Sum:
=Sum(Fields!Internet_Sales_Count.Value, "DataSet1")
Is there a way to get the 2008 value and subtract the 2005 value?
Here is one possibility:
WITH
MEMBER [Measures].[Internet Sales diff] AS
(
[Delivery Date].[Calendar Year].CurrentMember
,[Measures].[Internet Sales Amount]
)
-
(
[Delivery Date].[Calendar Year].CurrentMember.Lag(1)
,[Measures].[Internet Sales Amount]
), format_string = '#,###,###,##0.00'
SELECT
NON EMPTY
{
[Measures].[Sales Amount]
,[Measures].[Total Product Cost]
,[Measures].[Internet Sales Amount]
,[Measures].[Internet Sales diff]
} ON COLUMNS
,NON EMPTY
{[Delivery Date].[Calendar Year].[Calendar Year].ALLMEMBERS}
DIMENSION PROPERTIES
MEMBER_CAPTION
,MEMBER_UNIQUE_NAME
ON ROWS
FROM [Adventure Works];
The result of the above is the following:
A percentage measure could then be added like this:
WITH
MEMBER [Measures].[Internet Sales diff] AS
(
[Delivery Date].[Calendar Year].CurrentMember
,[Measures].[Internet Sales Amount]
)
-
(
[Delivery Date].[Calendar Year].CurrentMember.Lag(1)
,[Measures].[Internet Sales Amount]
)
,format_string = '#,###,###,##0.00'
MEMBER [Measures].[Internet Sales diff %] AS
IIF
(
[Measures].[Internet Sales Amount] = 0
,null
,
[Measures].[Internet Sales diff]
/
(
[Delivery Date].[Calendar Year].CurrentMember.Lag(1)
,[Measures].[Internet Sales Amount]
)
)
,format_string = '#,###,###,##0.00%'
SELECT
NON EMPTY
{
[Measures].[Sales Amount]
,[Measures].[Total Product Cost]
,[Measures].[Internet Sales Amount]
,[Measures].[Internet Sales diff]
,[Measures].[Internet Sales diff %]
} ON COLUMNS
,NON EMPTY
{[Delivery Date].[Calendar Year].[Calendar Year].ALLMEMBERS}
DIMENSION PROPERTIES
MEMBER_CAPTION
,MEMBER_UNIQUE_NAME
ON ROWS
FROM [Adventure Works];
Results in this:
Here is a better approach using the parallelperiod function:
WITH
MEMBER [Measures].[Internet Sales PrevYr] AS
IIF
(
[Measures].[Internet Sales Amount] = 0
,null
,(
[Measures].[Internet Sales Amount]
,ParallelPeriod
(
[Delivery Date].[Calendar Year].[Calendar Year]
,1
,[Delivery Date].[Calendar Year].CurrentMember
)
)
)
,format_string = '$#,###,###,##0.00'
MEMBER [Measures].[Internet Sales diff] AS
IIF
(
[Measures].[Internet Sales Amount] = 0
,null
,
[Measures].[Internet Sales Amount] - [Measures].[Internet Sales PrevYr]
)
,format_string = '$#,###,###,##0.00'
MEMBER [Measures].[Internet Sales diff %] AS
IIF
(
[Measures].[Internet Sales PrevYr] = 0
,null
,
[Measures].[Internet Sales diff] / [Measures].[Internet Sales PrevYr]
)
,format_string = '#,###,###,##0.00%'
SELECT
NON EMPTY
{
[Measures].[Internet Sales Amount]
,[Measures].[Internet Sales PrevYr]
,[Measures].[Internet Sales diff]
,[Measures].[Internet Sales diff %]
} ON COLUMNS
,NON EMPTY
{[Delivery Date].[Calendar Year].[Calendar Year].MEMBERS} ON ROWS
FROM [Adventure Works];
Results:
I am trying to implement something as follows:
WITH MEMBER Measures.Test2 AS
Sum
(
{
[Date].[Calendar].[Calendar Year].&[2006]
,[Date].[Calendar].[Calendar Year].&[2007]
}
,[Measures].[Internet Sales Amount]
)
SELECT Measures.Test2 ON COLUMNS
FROM [Adventure Works];
But i want the new measure Test2 to be sliceable according to the Calendar Year dimension. So i want something like
SELECT {Measures.Test2} ON 0,
{[Date].[Calendar].[Calendar Year].[Calendar Year].MEMBERS} ON 1
FROM [Adventure Works];
This is giving the same value for both the years 2006 and 2007.
In essence i want to create a member by taking a subset of an existing measure and then using it for further calculations
This script is not valid mdx:
SELECT (Measures.Test2,[Date].[Calendar].[Calendar Year].[Calendar Year] ON COLUMNS
FROM [Adventure Works];
You have a single ( before Measures.
Also you look like you're about to add a tuple ON COLUMNS which is not allowed. Only sets are allowed on rows and columns:
SELECT
{Measures.Test2} ON 0,
{[Date].[Calendar].[Calendar Year].[Calendar Year].MEMBERS} ON 1
FROM [Adventure Works];
Try the following:
WITH
MEMBER Measures.Test2 AS
Sum
(
Intersect
(
{[Date].[Calendar].CurrentMember}
,{
[Date].[Calendar].[Calendar Year].&[2006]
,[Date].[Calendar].[Calendar Year].&[2007]
}
)
,[Measures].[Internet Sales Amount]
)
SELECT
[Measures].test2 ON COLUMNS
,{[Date].[Calendar].[Calendar Year].MEMBERS} ON ROWS
FROM [Adventure Works];
The above returns this:
Or maybe all you want is a subselect:
SELECT
[Measures].[Internet Sales Amount] ON COLUMNS
,{[Date].[Calendar].[Calendar Year].MEMBERS} ON ROWS
FROM
(
SELECT
{
[Date].[Calendar].[Calendar Year].&[2006]
,[Date].[Calendar].[Calendar Year].&[2007]
} ON 0
FROM [Adventure Works]
);
I have the following expression MDX :
isnull([Measures].[Available Hours],0)
After processing cube I got the following error in reporting :
No appropriate overload function was found for the stored procedure
.The parameters are incorrect .MdxScript Execution of the managed
stored procedure isnull failed with the following error :Microsoft
AnalysisServices AdomdServer AdomdException
How to resolve the error ?
isnull is not an mdx function.
To test for null in mdx try using iif
iif(
[Measures].[Available Hours] = 0,
0,
[Measures].[Available Hours]
)
It looks a little strange as we look for 0 and then if it is 0 change it to 0!!
But here is an example:
WITH
MEMBER [Measures].[Internet Sales Amount 2] AS
IIF
(
[Measures].[Internet Sales Amount] = 0
,0
,[Measures].[Internet Sales Amount]
)
SELECT
{
[Measures].[Internet Sales Amount]
,[Measures].[Internet Sales Amount 2]
} ON 0
,
[Customer].[Customer Geography].[Country].MEMBERS
*
[Product].[Category].MEMBERS ON 1
FROM [Adventure Works];
This is what happens:
Edit
Alternative by #MarcPolizzi does the same thing and his code is more compact:
WITH
MEMBER [Measures].[Internet Sales Amount 2] AS
IIF
(
[Measures].[Internet Sales Amount] = 0
,0
,[Measures].[Internet Sales Amount]
)
MEMBER [Measures].[Internet Sales Amount 3] AS
CoalesceEmpty
(
[Measures].[Internet Sales Amount]
,0
)
SELECT
{
[Measures].[Internet Sales Amount]
,[Measures].[Internet Sales Amount 2]
,[Measures].[Internet Sales Amount 3]
} ON 0
,
[Customer].[Customer Geography].[Country].MEMBERS
*
[Product].[Category].MEMBERS ON 1
FROM [Adventure Works];
You could use the CoalesceEmpty function to replace null/empty values. To replace them with a 0 value you can do the following:
CoalesceEmpty([Measures].[Available Hours], 0)
Hope that helps.
i have this query, i need to implement for two dimension
WITH
SET [TCat] AS
TopCount([Product].[Subcategory].[Subcategory],10,[Measures].[Sales Amount])
MEMBER [Product].[Subcategory].[Other] AS
Aggregate([Product].[Subcategory].[Subcategory] - TCat)
SELECT { [Measures].[Sales Amount] } ON COLUMNS,
TCat + [Other] ON ROWS
FROM [Adventure Works]
I try but it is not working for two dimension
WITH
SET FIPS as
[Geography].[State-Province].[State-Province]
//TopCount([Product].[Subcategory].[Subcategory],10,[Measures].[Sales Amount])
SET [TCat] AS
Generate( {FIPS}, CrossJoin( {[Geography].[State-Province].CurrentMember}, topsum( ([Product].[Subcategory].[Subcategory]), 2, [Measures].[Sales Amount] ) ))
MEMBER [Product].[Subcategory].[Other] AS
Aggregate(Except( [Product].[Subcategory].[Subcategory].Members, TCat))
SELECT
{ [Measures].[Sales Amount] } ON COLUMNS,
Union(
TCat , {[Geography].[State-Province].[State-Province],[Product].[Subcategory].[Other]} ) ON ROWS
FROM [Adventure Works];
Try using Except.
WITH
SET [TCat] AS
TopCount([Product].[Subcategory].[Subcategory],10,[Measures].[Sales Amount])
MEMBER [Product].[Subcategory].[Other] AS
Aggregate(Except( [Product].[Subcategory].[Subcategory].Members, TCat)
SELECT { [Measures].[Sales Amount] } ON COLUMNS,
Union( TCat , {[Product].[Subcategory].[Other]} ) ON ROWS
FROM [Adventure Works]