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!
Related
I have a SSAS multidimensional cube and i am trying to calculate a denominator for a query by using a scope statement.
I am trying to assign the measure "Total SalesCumulative" the total value of all the sales for all the stores. I want this to stay being the total value and not get sliced when in a pivot table. The measure called Total Sales sums up all the sales for each store. I have gotten as far as the below but this just returns the value for each store and shows the same value as Total Sales.
SCOPE ([Measures].[Total SalesCumulative],[Dim Store].[Store Name].members);
THIS = ([Dim Store].[Store Name].[All],[Measures].[Total Sales]);
END SCOPE;
Has anyone got any suggestions how I can amend this?
I have checked your formula on Adventure Works database, and it seems correct. Just to be sure, you can check what you get with the query like the one below in SSMS (without making scope assignment):
with member measures.[All Order Count] as
([Measures].[Internet Order Count],[Product].[Model Name].[All Products] )
select {[Measures].[Internet Order Count] ,measures.[All Order Count] } on 0,
[Product].[Model Name].members on 1
from [Adventure Works]
Have you tried to clear cash before running the query after you made the change?
Secondly, maybe there is some other scope assignment in the script, that affects the same measure and dimension and overrides your formula, because the last scope assignment wins.
Try to add FREEZE(THIS) to your scope statement just to check if it will change the numbers:
SCOPE ([Measures].[Internet Order Count],[Product].[Model Name].members);
THIS = ([Product].[Model Name].[All Products] , [Measures].[Internet Order Count]) ;
FREEZE(THIS);
END SCOPE;
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:
I want to be able to create the following table in SSRS:
StoreKey StorePercentage
1024 50 %
1037 20 %
1111 13 %
1949 27 %
where I've encountered that it was not possible to create a chart using Aggregated data. Hence I try to specify the StorePercentage value in SSAS (as I am using an analysis server as a data source in SSRS) and import that into SSRS and use the value off the bat. With the purpose of creating this data set I've started to test this query in SSMS:
With MEMBER [Measures].[StorePercentage] AS
SUM (
{
[Dim Store2].[Store Key],[Dim Date].[Calender].[Date].[2014-11-23]:[Dim Date].[Calender].[Date].[2014-11-29]
}, [Measures].[Total Price]
)
/ SUM
(
{
[Dim Date].[Calender].[Date].[2014-11-23]:[Dim Date].[Calender].[Date].[2014-11-29]
}, [Measures].[Total Sales]
)
Select non empty
{
[Measures].[Total Price],[Measures].[StorePercentage]
} on 0,
[Dim Store2].[Store Key].children on 1
FROM [theyseemecubintheyhatin]
But this gives me:
StoreKey Total Price StorePercentage
1024 50424 #Error
1037 3434 #Error
1111 1333 #Error
1949 2443 #Error
, i.e. my calculated measure seem to be problematic.
What I essentially try to do in the query, in the With MEMBER clause is:
SUM(Total sale made by each store and date range separately)/SUM(Total Sales for all stores over the time interval)
but I seem to be having some issues with this. I've tried a bunch of different combinations of {,( in the query but I haven't gotten it to work.
Does anyone have a clue? When I tried to Google this issue, the queries I found were related to getting data for a measure and a specific date range, but I need to query for each store as well.
I think it will make more sense:
With
Member [Measures].[StorePercentage] AS
[Measures].[Total Price]
/
([Dim Store2].[Store Key].[All],[Measures].[Total Price])
select
non empty {[Measures].[Total Price],[Measures].[StorePercentage]} on 0,
non empty [Dim Store2].[Store Key].[Store Key].Members on 1
from [theyseemecubintheyhatin]
where ({[Dim Date].[Calender].[Date].[2014-11-23]:[Dim Date].[Calender].[Date].[2014-11-29]})
The problem code is here:
{[Dim Store2].[Store Key],[Dim Date].[Calender].[Date].[2014-11-23]:[Dim Date].[Calender].[Date].[2014-11-29]}
Because [Dim Store2].[Store Key] doesn't mean anything.
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 using Performance Point Dashboard Designer 2013 and SharePoint Server 2013 for building dashboards. I am using SSAS2012 for Cube.
I have a scenario similar to the one illustrated by figure below. I am required to find Previous Non-Empty value for purpose of finding Trends.
Measure: [Quota]
Dimension: [Date].[Calendar Date].[Date]
The script ([Measures].[Quota], [Date].[Calendar Date].PrevMember) gives you a previous date. Lets say for date 27-Jan-13 whose Quota value is 87, it returns 26-Jan-13 which has null value. I want it to return 21-Jan-13 that has some Quota value. And for date 21-Jan-13, I want to return 15-Jan-13.
I wonder if this is possible.
Thanks,
Merin
After long searches and hits & trials and so on, I think I invented a solution of my own for myself.
Following is the script for my Calculated Member.
(
[Quota],
Tail
(
Nonempty
( LastPeriods(15, [Date].[Calendar Date].PrevMember)
,[Quota]
)
).Item(0)
)
Explanation
The number 15 means it will look for non-empty measures up to 15 siblings.
Now we know up to how many siblings to traverse back, in this case 15.
Lets find 15 previous siblings (both empty and non-empty) excluding current member.
(LastPeriods(15, [Date].[Calendar Date].PrevMember)
Since it will yield both empty and non-empty members, lets filter out empty members in terms of measure [Quota]. If we don't specify measure here, it will use default measure whatever it is and we may not get desired result.
Nonempty(LastPeriods(15, [Date].[Calendar Date].PrevMember),[Quota])
We may have several members in the output. And we will choose the last one.
Tail
(
Nonempty
( LastPeriods(15, [Date].[Calendar Date].PrevMember)
,[Quota]
)
)
So far, the script above gives previous non-empty member. Now we want to implement this member for our measure [Quota].
Hence we get the script below ready to create a Calculated Member.
(
[Quota],
Tail
(
Nonempty
( LastPeriods(15, [Date].[Calendar Date].PrevMember)
,[Quota]
)
).Item(0)
)
You can use recursion to define this.
The following query delivers something similar for the Adventure Works cube:
WITH member [Measures].[Prev non empty] AS
IIf(IsEmpty(([Date].[Calendar].CurrentMember.PrevMember, [Measures].[Internet Sales Amount])),
([Date].[Calendar].CurrentMember.PrevMember, [Measures].[Prev non empty]),
([Date].[Calendar].CurrentMember.PrevMember, [Measures].[Internet Sales Amount])
), format_String = '$#,##0.00'
SELECT {[Measures].[Internet Sales Amount], [Measures].[Prev non empty]}
ON COLUMNS,
non empty
Descendants([Date].[Calendar].[Month].&[2007]&[12], [Date].[Calendar].[Date])
ON ROWS
FROM [Adventure Works]
WHERE [Customer].[Customer].&[12650]
You would have to replace the name of the date hierarchy, as well as the measure name from Internet Sales Amount to Quota in the recursive definition of the measure Prev non empty.