I have a dimension [product].[type] having its member containing 'Food','Book','Metal','Meat', etc. My task is to show a categorized dimension to group my sales value, such as, group Food & Meat as 0, Metal & Tool as 1, Book as 2, etc..
My Query seems doesn't work:
WITH calculated member [Measures].[Grouped Type] AS
IIF([product].[type].CurrentMember IS [product].[type].[Meat], 0,
IIF([product].[type].CurrentMember IS [product].[type].[Food], 0,
IIF([product].[type].CurrentMember IS [product].[type].[Tool], 1,
...... , 9)))))
SELECT {[Measures].[Sales Amount], [Measures].[Grouped Type].Children} on 0
FROM Cube
WHERE ([Condition])
It looks my total sales amount is shown, but not correctly categorized. any help? Appreciated.
Try calculated members against the product dimension, not measure's one:
With
Member [product].[type].[0] as
Sum({[product].[type].[Meat],[product].[type].[Food]})
Member [product].[type].[1] as
Sum({[product].[type].[Tool]})
select
[Measures].[Sales Amount] on 0,
{[product].[type].[0],[product].[type].[1]} on 1
From Cube
Where ([Condition])
Related
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:
With the function TopPerent, you can get the set of members - ordered top down - that comply to the % value provided.
I would like to switch this function and get the cumulative % given the member.
Description of the image:
TopPercent in icCube, all countries in Excel ordered top down on Amount. Cum % caluclated. The BLUE highlighted values indicate the value I would like to obtain
I hope it will be enough to understand the point:
With
Set [OrderedCity] as
Order([Customer].[City].[City].Members,[Measures].[Internet Sales Amount],DESC)
Member [Measures].[Cum] as
Sum(
Head([OrderedCity],Rank([Customer].[City].CurrentMember,[OrderedCity])),
[Measures].[Internet Sales Amount]
)
Member [Measures].[Cum %] as
[Measures].[Cum] / ([Customer].[City].[All],[Measures].[Internet Sales Amount]),
Format_String = "Percent"
Select
Non Empty [OrderedCity] on 1,
{[Measures].[Internet Sales Amount],[Measures].[Cum],[Measures].[Cum %]} on 0
From [Adventure Works]
I would like to define a measure that will count dimension members by other dimension and add it as a measure on the cube.
Should I create a new measure group with a count of the attribute of dimension or it's better to create a calculated member?
Example on adventureworks: count products by ProductCategory
WITH
MEMBER [Measures].[Number of Products] AS
Count(Existing
[Product].[Product].[Product].Members
)
SELECT
[Measures].[Number of Products] on 0,
{[Product].[Category].Members} ON ROWS
FROM [Adventure Works]
You haven't given details, but my guess is that your current code will return the count of all products, repeated for each Product Category.
I don't have a working copy of Adventureworks to hand, but if Product is a level one level below Product Category in hierarchy "ProductHierarchy" on the Product dimension, this should work:
WITH MEMBER [Measures].[Number of Products] AS
Count([Product].[ProductHierarchy].CurrentMember.Descendants)
SELECT
[Measures].[Number of Products] ON 0,
{[Product].[Category].Members} ON 1
FROM [Adventure WOrks]
I got a cube with cadastral information of some neighborhoods of a city. One of the measures is 'cadastral value': the value of the land of a neighborhood.
Now, the city is divided into districts and a district, into neighborhoods (hierarchy with two levels).
The question is: I need to calculate the percentage that the value of each neighborhood represents compared with the parent (the district) and with the total (city), and also the same about the district compared with the city.
How can I do it?
I tried:
WITH MEMBER
[Measures].[Percentage] AS
([Nbh].[Nbh].[Nbh],[Measures].[Cad value].CurrentMember
/[Nbh].[Nbh].[Nbh],[Measures].[Cad value].CurrentMember.Parent)
SELECT
{[Measures].[Percentage]} ON 0,
[Nbh].[Nbh].[Nbh].AllMembers ON 1
FROM Cadastre
Where the dimensions are:
Nbh : Neighborhood
Cad value: Cadastral value
What I get is "error" in every result value, and the explanation is "Current member () : argument (0) type mismatch: expected:'level|hierarchy|dimension', got:'measure'"
What am I doing wrong?
WITH MEMBER [Measures].[Percentage] AS
([Nbh].[Nbh].[Nbh],[Measures].[Cad value].CurrentMember
/[Nbh].[Nbh].[Nbh],[Measures].[Cad value].CurrentMember.Parent)
There are two problems with this:
One, you are using a static set to compute the value of calculated member namely:
[Nbh].[Nbh].[Nbh]
This is NOT [Nbh].[Nbh].CURRENTMEMBER
Second and the bigger mistake: Using the currentmember on a measure. You can't do that. You can use Measures.CURRENTMEMBER but that's about it. It's best used on hierarchies which are used on axes.
That said, your approach is almost legit. You need to fetch the measure value for the parent.
This should work:
WITH MEMBER
[Measures].[Percentage] AS
DIVIDE
(
[Measures].[Cad value],
([Nbh].[Nbh].CURRENTMEMBER.PARENT,[Measures].[Cad value]) //Cad value for parent
)
SELECT
{[Measures].[Percentage]} ON 0,
[Nbh].[Nbh].[Nbh].AllMembers ON 1
FROM Cadastre
Try the following:
WITH MEMBER [Measures].[Parent %] AS
IIF(
[Nbh].[Nbh].CURRENTMEMBER IS [Nbh].[Nbh].[All]
,1
,[Measures].[Cad value] /
(
[Measures].[Cad value],
[Nbh].[Nbh].CurrentMember.Parent
)
), FORMAT_STRING = 'Percent'
SELECT
{[Measures].[Parent %]} ON 0,
[Nbh].[Nbh].[Nbh].AllMembers ON 1
FROM Cadastre;
Including the IIF is a defensive measure. If you switch to showing AllMembers of the complete hierarchy then the All member will be included. Here is an example using AdvWrks:
WITH
MEMBER [Measures].[Parent %] AS
IIF
(
[Product].[Subcategory].CurrentMember
IS
[Product].[Subcategory].[All Products]
,1
,
[Measures].[Internet Sales Amount]
/
(
[Measures].[Internet Sales Amount]
,[Product].[Subcategory].CurrentMember.Parent
)
)
,FORMAT_STRING = 'Percent'
SELECT
NON EMPTY
{[Measures].[Parent %]} ON 0
,NON EMPTY
[Product].[Subcategory].ALLMEMBERS ON 1
FROM [Adventure Works];
The above returns the following:
Without the IIF the expression is the following:
WITH
MEMBER [Measures].[Parent %] AS
[Measures].[Internet Sales Amount]
/
(
[Measures].[Internet Sales Amount]
,[Product].[Subcategory].CurrentMember.Parent
)
,FORMAT_STRING = 'Percent'
SELECT
NON EMPTY
{[Measures].[Parent %]} ON 0
,NON EMPTY
[Product].[Subcategory].ALLMEMBERS ON 1
FROM [Adventure Works];
We get the following because of lack of foresight:
The error is certainly because of this statement is incorrect:
WITH MEMBER
[Measures].[Percentage]
AS ([Nbh].[Nbh].[Nbh],[Measures].[Cad value].CurrentMember/[Nbh].[Nbh].[Nbh],[Measures].[Cad value].CurrentMember.Parent)
Try to make it like this
WITH MEMBER
[Measures].[Percentage]
AS ([Nbh].[Nbh].[Nbh],[Measures].[Cad value])/([Nbh].[Nbh].[Nbh],[Measures].[Cad value])
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