This calc works fine for grade code in the grade dimension
CREATE MEMBER CURRENTCUBE.[Measures].[Daily Headcount Percentage by Grade]
AS [Measures].[Headcount]
/
([Grade].[Grade Code].[All], [Measures].[Headcount]),
FORMAT_STRING = "Percent"
I'd like for the calc to work against any of the attributes in the grade dim as currently all but grade code returns 100%?
A quick test on a local cube, removing the attribute worked for me does it work for you?
CREATE MEMBER CURRENTCUBE.[Measures].[Daily Headcount Percentage by Grade]
AS [Measures].[Headcount]
/
([Grade].[All], [Measures].[Headcount]),
FORMAT_STRING = "Percent"
Related
I was able to calculate PY Total for Selected Time Dimension's Attributes in individual Hierarchy but cannot figure out how to make it work for both Time Dimension Hierarchies with single calculated measure.
I had to USE Dynamic SET to populate Days and use AGGREGATE on the SET as follows -
CREATE DYNAMIC SET CURRENTCUBE.[Days]
AS {EXISTING [Time].[Time].[Day]};
CREATE MEMBER CURRENTCUBE.[Measures].[PY Sales Selected]
AS AGGREGATE(
GENERATE(EXISTING [Days],
{PARALLELPERIOD([Time].[Time].[Year],1,[Time].[Time].CurrentMember)}
),
[Measures].[Sales]
),
FORMAT_STRING = "#,#",
VISIBLE = 1
----
CREATE DYNAMIC SET CURRENTCUBE.[Days]
AS {EXISTING [Time].[Current].[Curr Day Flag]};
CREATE MEMBER CURRENTCUBE.[Measures].[PY Sales Selected]
AS AGGREGATE(
GENERATE(EXISTING [Days],
{PARALLELPERIOD([Time].[Current].[Curr Year Flag],1,[Time].[Current].CurrentMember)}
),
[Measures].[Sales]
),
FORMAT_STRING = "#,#",
VISIBLE = 1
Both calculations work individually but I would like to combine them so that I could just have one Calculated Measure [Measures].[PY Sales Selected].
We have following Time dimension structure -
I would appreciate any help!!
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;
I have this MDX;
CREATE MEMBER CURRENTCUBE.[Measures].DistinctOrderCount<br/>
AS
DistinctCount([Order].[Order Id].[Order Id] - [Order].[Order Id].[1]),<br/>
FORMAT_STRING = "#,##0;-#,##0",
VISIBLE = 1, ASSOCIATED_MEASURE_GROUP = 'Fact Sales';
I am trying to do a distinct of orders (except Order Id=1) within the context of other dimensions in my fact table. For example, distinct order count by dim customers, dim city, dim state etc. but I am not able to achieve this. When I view my measure on a report, I get distinct count of order dimension which is 21 being displayed on all rows of customers.
This is the best way I solved this and I am happy with the results. Hope this may help others. The idea is, create a cube measure with aggregation type Distinct Count and set column binding on the column you want distinct count on. Then use the below MDX to filter out the dummy Order Id's from your distinct count.
create member currentcube.[Measures].OrderCount<br/>
as<br/>
distinctcount
(
existing
CROSSJOIN
(
Except([Orders].[Order Id].[Order Id], [Orders].[Order Id].&[1]),
[Measures].[Order Count]
)
),<br/>
FORMAT_STRING = "#,##0;-#,##0",
VISIBLE = 1, ASSOCIATED_MEASURE_GROUP='Order Count';
SELECT NON EMPTY {{[Measures].[Net Promoter Score],[Measures].[AvgRevenuePerUnit]}} ON COLUMNS ,
NON EMPTY {{Hierarchize(DrilldownLevel(DrilldownLevel(DrilldownLevel([Employees].[Boss].[ALL]))))}}
ON ROWS
FROM (SELECT ({[Employees].[Boss].&[14404]}) ON COLUMNS
FROM [Enterprise]
WHERE FILTER([Employees].[EID].[EID],[Measures].[Avg Revenue Per Unit] > 700))
WHERE ({[Employees].[Active Status].&[False]},{[Roles].[Roster Role].&[486]},{[Roles].[Enterprise Role].&[2]},
{[Locations].[Location].&[6]},{[Areas].[Area].&[3]},{[Markets].[Market].&[1]},{[Regions].[Region].&[2]},
{[Dates].[Date].&[20130218]:[Dates].[Date].&[20130319]})
When I run above query, AvgRevenuePerUnit column shows 1.#INF. To replace 1.#INF with 0, I used query given below but the result is same. I am using WITH MEMBER in a query given below.
WITH MEMBER [Measures].[AvgRevenuePerUnit] AS (IIF([Measures].[Avg Revenue Per Unit] = '1.#INF', 0, [Measures].[Avg Revenue Per Unit])), Format_String = '0.#0'
SELECT NON EMPTY {{[Measures].[Net Promoter Score],[Measures].[AvgRevenuePerUnit]}} ON COLUMNS ,
NON EMPTY {{Hierarchize(DrilldownLevel(DrilldownLevel(DrilldownLevel([Employees].[Boss].[ALL]))))}}
ON ROWS
FROM (SELECT ({[Employees].[Boss].&[14404]}) ON COLUMNS
FROM [Enterprise] WHERE FILTER([Employees].[EID].[EID],[Measures].[Avg Revenue Per Unit] > 700))
WHERE ({[Employees].[Active Status].&[False]},{[Roles].[Roster Role].&[486]},{[Roles].[Enterprise Role].&[2]},
{[Locations].[Location].&[6]},{[Areas].[Area].&[3]},{[Markets].[Market].&[1]},{[Regions].[Region].&[2]},
{[Dates].[Date].&[20130218]:[Dates].[Date].&[20130319]})
I have a cube provided by user and from that cube I query data. It seems to me that actual value in cube is not 1.#INF that's why it doesn't replace with 0. But what is that value if it is not 1.#INF.
Any solution ?
1.#INF or -1.#INF is how Analysis Services displays plus/minus infinity, which technically/mathematically is the result of dividing something by zero.
The best approach to avoid this is in the definition of the measure, which is probably in the calculation script of the cube. You probably have there something like
CREATE MEMBER CurrentCube.[Measure].[AvgRevenuePerUnit] AS A / B
, VISIBLE = 1;
Replace this with
CREATE MEMBER CurrentCube.[Measure].[AvgRevenuePerUnit] AS IIf(B <> 0, A / B, null)
, VISIBLE = 1;
and you are done. Of course, replace A and B as appropriate.
Note: There was a recent update for Analysis Services 2012 which contains a new MDX function Divide which allows to write
CREATE MEMBER CurrentCube.[Measure].[AvgRevenuePerUnit] AS Divide(A, B)
, VISIBLE = 1;
If you and all other users really have to stick with the definition as it is in the cube, and have to rely on WITH clauses in queries, then I think your code could be written like
WITH MEMBER [Measures].[AvgRevenuePerUnit] AS
IIF([Measures].[Avg Revenue Per Unit] = 1 / 0 -- '1.#INF', plus infinity
OR [Measures].[Avg Revenue Per Unit] = -1 / 0, -- '-1.#INF', minus infinity
0,
[Measures].[Avg Revenue Per Unit]),
Format_String = '0.#0'
...
Your approach of using '1.#INF' does not work, as this is a string, and the infinite numbers are numbers and not strings for Analysis Services.
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!