I found that mondrian dont use aggregate table for average measure if WHERE is exist. How to be with it?
SELECT [Measures].[Avg measure] on COLUMNS,
VisualTotals(Hierarchize({Set of dimension #1})) om ROWS
FROM [Cube name]
WHERE {set of dimension #2}
I'm not sure, but you may give a try to the sub query:
SELECT [Measures].[Avg measure] on COLUMNS,
VisualTotals(Hierarchize({Set of dimension #1})) om ROWS
FROM [Cube name]
WHERE (select from [Cube name] where {set of dimension #2})
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:
I have just started to work with OLAP Cubes. I have some questions about MDX queries. I have a query like:
WITH
MEMBER [Balance].[NegEXPENSE] AS '-[Balance].[Type].[EXPENSE]'
SET BalanceTypeSet AS {[Balance].[Type].[INCOME], [Balance].[NegEXPENSE]}
MEMBER [Balance].[TypeSum] AS AGGREGATE(BalanceTypeSet)
SELECT {Measures.[Sum]} ON COLUMNS,
{[Balance].[Type].[INCOME], [Balance].[Type].[EXPENSE], [Balance].[TypeSum]} ON ROWS
FROM [Balance Cube]
The result of this query like:
RESULT
This result doesn't have a name of the last row(TypeSum). How can I add a name for TypeSum?
Thanks.
You need to add calculated dimension member, try this:
WITH
MEMBER [Balance].[Type].[TypeSum] AS AGGREGATE(BalanceTypeSet)
SELECT {[Measures].[Sum]} ON COLUMNS,
{[Balance].[Type]} ON ROWS
FROM [Balance Cube]
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';
I would like to add a measure that has different dimensionality to the same SELECT mdx statement. In general, most of my measures are linked to [Customer Creation Date].[Date Hierarchy].[Month Name].
However, Anonymous customers do not have the link to customer creation date; therefore, I have to link anonymous to Enquiry Creation Date. How to combine two measures into single select query.
> WITH MEMBER [Measures].[Allow Contact] as
([Measures].[# CRM Customers],[Customer].[Customer Allow Contact].&[Yes],[Customer].[Customer Status].&[Active] )
MEMBER [Measures].[Total Identified Customers] AS
([Measures].[# CRM Customers],[Customer].[Customer Status].&[Active] )
MEMBER [Measures].[Anonymous Customers] AS
([Measures].[# Unique Distinct Customers on Contact],[Enquiry].[Anonymous].&[Yes])
SELECT NON EMPTY { Measures].[Allow Contact],
[Measures].[Total Identified Customers]
//,[Measures].[Anonymous Customers]
} ON COLUMNS
,NON EMPTY ([Customer Creation Date].[Date Hierarchy].[Month Name]
//,[Enquiry Creation Date].[Date Hierarchy].[Month Name] //How to add different dimensionality
) ON ROWS
FROM [Cube]
If both time dimensions have the same structure (which should obviously be the case if they are implemented as role playing dimensions on the same dimension object), you can use the LinkMember function in the definition of [Measures].[Anonymous Customers] to use the [Customer Creation Date].[Date Hierarchy] in the rows, but use these dates as the [Enquiry Creation Date].[Date Hierarchy] in the measure calculation:
WITH MEMBER [Measures].[Allow Contact] as
([Measures].[# CRM Customers],[Customer].[Customer Allow Contact].&[Yes],[Customer].[Customer Status].&[Active] )
MEMBER [Measures].[Total Identified Customers] AS
([Measures].[# CRM Customers],[Customer].[Customer Status].&[Active] )
MEMBER [Measures].[Anonymous Customers] AS
([Measures].[# Unique Distinct Customers on Contact],[Enquiry].[Anonymous].&[Yes],
LinkMember([Customer Creation Date].[Date Hierarchy].CurrentMember, [Enquiry Creation Date].[Date Hierarchy])
SELECT NON EMPTY { Measures].[Allow Contact],
[Measures].[Total Identified Customers]
,[Measures].[Anonymous Customers]
} ON COLUMNS
,NON EMPTY ([Customer Creation Date].[Date Hierarchy].[Month Name]
) ON ROWS
FROM [Cube]
SELECT
NON EMPTY {[Measures].[Fact Order Count]}
ON COLUMNS,
{ ([Front Manager].[Front Manager Id].[Front Manager Id].ALLMEMBERS * [Order Type].[Order Type].[Order Type].ALLMEMBERS ) }
ON ROWS
FROM
[TEST_DW] CELL PROPERTIES VALUE
So, I have three columns in the output:
Front Manager, Order Type, Order Count
The above query shows me the counts for each manager and order type combination. I need a fourth column which would be a percentage of the types of orders for each front manager.
So, if there are four types of orders (A, B, C, D), and a manager had 25 of each order totaling 100. The fourth column would read 25%.....
I have scoured the web on how to do this, but have really come up short on this one. Any direction on this would be greatly appreciated, I am definitely new to MDX. Thanks.
What you're looking for are MDX Calculated members.
Let's assume the member for order A is called : [Order Type].[Order Type].[Order A] and we want to calculate the percentage from the total.
WITH
MEMBER [Order A] AS ([Order Type].[Order Type].[Order A],[Measures].[Fact Order Count]) / ([Measures].[Fact Order Count]) , FORMAT_STRING = 'Percent'
SELECT
{[Measures].[Fact Order Count],[Measures].[Order A]} on 0
...
What is important in the calculated members is that you can evaluate any MDX tuple (e.g ([Order Type].[Order Type].[Order A],[Measures].[Fact Order Count]) ). This changing if needed the values coming from the pivot axis (defined in on 0 and on 1..). Note you can add calculated members for the measures as well as the other dimensions.