Please consider this scenarios:
I have a cube with one Fact table and one measure called SalesAmount . Now I want to create a measure based on these 2 Selects:
Select 1:
Select [Measures].[SalesAmount]
From MyCube
Where [Product].[Color].[Gray]
and Select 2:
Select [Measures].[SalesAmount]
From MyCube
Where [Dates].[Calendar Year].&[2015]
The problem is in Add Calculate Member there is a box for simple formula. How can I create a measure for Select 1 + Select 2?
Thanks
I am not sure where are you looking at this Add Calculate Member option, but you could try something like this (Adventure Works database).
with member measures.[MyMeasure1]
as
([Measures].[Internet Sales Amount], [Date].[Calendar].[Calendar Year].&[2006])
member measures.[MyMeasure2]
as
([Measures].[Internet Sales Amount], [Product].[Color].&[Grey])
member measures.[MyMeasure12]
as
measures.[MyMeasure1] + measures.[MyMeasure2]
select {[Measures].[Internet Sales Amount], measures.[MyMeasure1], measures.[MyMeasure2] , measures.[MyMeasure12]} on 0
from [Adventure Works]
You can also create those members from Visual Studio Data Tools - in Calculations tab:
Related
I recently started encountering strange problem as shown in image below. While browsing a SSAS cube, the Dimension Names appear blank.
Dimension: I have [Date].[Calendar Month].[Month]
Measure: [Services in 3 days]
After I run a query like
Select [Date].[Calendar Month].[Month] on 0 From [Service Cube]
then the Dimension Member Names show up in cube browser with different value for measure.
Any clues?
That's because you have blank members in [Date].[Calendar Month] hierarchy. To check 'em out, run the below MDX query:
WITH SET BlankMonth AS
FILTER([Date].[Calendar Month].CHILDREN, [Date].[Calendar Month].currentmember.MEMBERVALUE = '')
SELECT [Measures].[Services in 3 days] ON 0,
BlankMonth ON 1
FROM [Service Cube]
I am trying to select the top 10 products by internet sales from the Adenture Works cube (the cube I managed to compile with the Analysis Services Tutorial), I managed to do the cube perfectly, now I need to add a filter to add a specific product line and a given month and I don't know how to build the query...
I have this working:
with
set productNames as head(order({[Product].[Model Name].children}, [Measures].[Internet Sales-Unit Price], desc), 10)
select [Measures].[Internet Sales-Unit Price] on 0,
productNames on 1
from [Analysis Services Tutorial]
I added the filter and the result is the same...
with
set productNames as head(order(
filter({[Product].[Model Name].children},[Product].[Product Model Lines].[Product Line].&[R] )
, [Measures].[Internet Sales-Unit Price], desc), 10)
select [Measures].[Internet Sales-Unit Price] on 0,
productNames on 1
from [Analysis Services Tutorial];
Note: I can't use the hierarchy, because on my production database (which is not adventure works) I don't have hierarchies setup for the given problem.
Take a look at this query:
SELECT
[Measures].[Internet Sales Amount] ON COLUMNS
, TOPCOUNT([Product].[Product Line].&[R]*[Product].[Model Name].[Model Name],10,[Measures].[Internet Sales Amount]) ON ROWS
FROM
[Adventure Works]
The FILTER function is designed to filter a set of members that conform to a particular condition e.g. having Sales greater than £1000. It is not suitable for filtering a set by other dimensions or attributes. For this you can use the CROSSJOIN as I have done above (the *) and also the NONEMPTY function.
I hope that helps,
Ash
One of the functions being used in a code sample is averageofchilren.
What exactly the AverageOfChildren aggregate function actually does?
How can we compare this with Avg() function in MDX ?
Maybe a custom measure is created in your cube.
Using AdventureWorks try this:
Script 1
SELECT
{[Measures].[Reseller Sales Amount]} ON 0,
NON EMPTY
{[Geography].[Geography].[Country].&[Australia].CHILDREN} ON 1
FROM [Adventure Works]
WHERE ([Date].[Calendar Year].&[2007])
That results in this:
Say I wanted to create a measure that returned the average reseller sales amount per region of each country then I could do the following:
Script 2
WITH
MEMBER [Measures].[AvgOfChildren] AS
AVG(
[Geography].[Geography].CURRENTMEMBER.CHILDREN,
[Measures].[Reseller Sales Amount]
)
SELECT
{ [Measures].[Reseller Sales Amount],
[Measures].[AvgOfChildren]
} ON 0,
{[Geography].[Geography].[Country].MEMBERS} ON 1
FROM [Adventure Works]
WHERE ([Date].[Calendar Year].&[2007])
You can see from the results for Australia (211,857.58) that the AverageOfChildren is the average of the numbers returned by script 1:
I am trying to create a dataset for an SSRS report as documented here:
http://sqlblog.com/blogs/stacia_misner/archive/2010/10/08/29249.aspx
The challenge is that I have multiple measures who's data I want to include in the measure column and I want to include the name of the measure in the RowValue column. So where the following query returns only data for measure "Sales Amount":
with
member [Measures].[Measure] as [Measures].[Sales Amount]
member [Measures].[RowValue] as [Product].[Category].CurrentMember.Name
member [Measures].[ColumnValue] as [Date].[Calendar Year].CurrentMember.Name
select {[Measures].[Measure], [Measures].[RowValue], [Measures].[ColumnValue]} on columns,
non empty ([Product].[Category].[Category].Members, [Date].[Calendar Year].[Calendar Year].Members) on rows
from [Adventure Works]
What I want to do is run the following type of query but have the data returned in the structure of the query above which would allow me to plug it into an SSRS report matrix:
WITH
MEMBER measures.SalesAmount AS [Measures].[Sales Amount]
MEMBER measures.CustomerCount AS [Measures].[Customer Count]
MEMBER measures.InternetFreightCost AS [Measures].[Internet Freight Cost]
SELECT [Date].[Calendar Year].[Calendar Year].Members ON COLUMNS,
{measures.SalesAmount,measures.CustomerCount,measures.InternetFreightCost} ON ROWS
FROM [Adventure Works]
Do any of the MDX ninjas know if this is even possible with MDX?
with member [Geography].[City].[Sales Amount] as 1
member [Geography].[City].[Customer Count] as 1
member [Geography].[City].[Freight Cost] as 1
member [Measures].[RowValue] as [Geography].[City].CurrentMember.Name
member [Measures].[ColumnValue] as [Date].[Calendar Year].CurrentMember.Name
member [Measures].[Measure] as
CASE
WHEN [Geography].[City].CurrentMember IS [Geography].[City].[Sales Amount]
THEN ([Measures].[Internet Sales Amount], [Geography].[City].[All Geographies])
WHEN [Geography].[City].CurrentMember IS [Geography].[City].[Customer Count]
THEN ([Measures].[Customer Count], [Geography].[City].[All Geographies])
WHEN [Geography].[City].CurrentMember IS [Geography].[City].[Freight Cost]
THEN ([Measures].[Internet Freight Cost], [Geography].[City].[All Geographies])
END
select {[Measures].[RowValue], [Measures].[ColumnValue], [Measures].[Measure]}
on columns,
{ [Geography].[City].[Sales Amount], [Geography].[City].[Customer Count], [Geography].[City].[Freight Cost]}
*
[Date].[Calendar Year].[Calendar Year].Members
having [Measures].[Measure] <> null
on rows
from [Adventure Works]
should deliver what you want. I used [Geography].[City] as an utility hierarchy. This can be any hierarchy unused in the query. I chose this one, as it is unrelated to both measure groups used in the query, and hence very unlikely to be used in any query. Some Cube designers create one or two one-member dummy dimensions in their cubes that are unrelated to any measure group, and can be used just like here in order to create calculated members on them.
One of the difficulties with ReportingServices queries is that measures must always be in the columns, and no other hierarchy may be in the columns. Hence, if we want to have the measures in the rows, we must move them to another hierarchy. This is done in two steps: First, we create dummy members on the utility hierarchy, and then map these to the measure needed in the CASE construct of the [Measures].[Measure] definition, where we need to use the default member of the utility dimension (in most cases the All member) in order to get something different than the 1 that I used for the dummy value.
Finally: non empty does not work properly with this construct, as [Measures].[RowValue] and [Measures].[ColumnValue] are never null. Hence I replaced it by HAVING, which can look at specific column values within the row.
I have a simple olap cube - one set of measures and some unexciting dimensions.
I've add one calculation to get the "percent of total" sales against the gross sales measure. The code for this calculation is:
([Dim Stores].[Store Name].CurrentMember, [Measures].[Gross Sales])
/
([Dim Stores].[Store Name].Parent, [Measures].[Gross Sales])
This works.
Within the store dimension, there is a hierarchy called 'By State' where the stores are contained within.
Two questions please:
1. Any idea why the calculation would not work when I use the the 'By state' hierarchy i.e. the same calculation grouped by the next level up?
The state problem aside, any idea why my grand total shows an error even when I just use the Store Name?
TIA!
In poking around, I found a template within the "calculation tools" called "Percentage of Total". Using it, I translated my calculation to this:
Case
// Test to avoid division by zero.
When IsEmpty
(
[Measures].[Gross Sales]
)
Then Null
Else ( [Dim Stores].[By State].CurrentMember, [Measures].[Gross Sales] )
/
(
// The Root function returns the (All) value for the target dimension.
Root
(
[Dim Stores]
),
[Measures].[Gross Sales]
)
End
It worked!