我正在学习MDX,我有一个问题要创建一个百分比。 基本上,我从Google Analytics API中提取多组网页的数据。 对于每个集合,我提取UniquePageviews的数量。
SQL列看起来像这样:
以下是我目前的观点: http://i.stack.imgur.com/ZTC30.png
我想要的是第1页到第2页以及第2页到第3页的UniquePageviews的百分比所以:UniquePageviews 2 / Uniquepageviews 1& UniquePageviews 3 / Uniquepageviews 2。
http://i.stack.imgur.com/xf2gc.png
您是否知道在MDX中使用这种方法的简单方法?
以下是我现在用于显示综合浏览量的代码:
WITH
SET [~COLUMNS_Brand_Brand] AS
SET [~COLUMNS_Market_Market] AS
{[Market].[Market].Members}
SET [~COLUMNS_set_of_page segment_set_of_page] AS
{[set_of_page].[set_of_page].Members}
SET [~ROWS] AS
{[Date].[Date].Members}
SELECT
NON EMPTY NonEmptyCrossJoin([~COLUMNS_Brand_Brand], NonEmptyCrossJoin([~COLUMNS_Market_Market], [~COLUMNS_set_of_page_set_of_page])) ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [MySQL_Cube]
非常感谢!
答案 0 :(得分:0)
当你的mdx
隐含地采取措施时?所有mdx查询都需要测量一些内容,因此您当前的脚本必须采用默认的多维数据集度量 - 我将其称为[Measures].[NumTransactions]
。
你的第一个SET似乎也是空白的。因此,我们假设完整的显式脚本是:
WITH
SET [~COLUMNS_Brand_Brand] AS {[Brand].[Brand].[All]}
SET [~COLUMNS_Market_Market] AS
{[Market].[Market].Members}
SET [~COLUMNS_set_of_page segment_set_of_page] AS
{[set_of_page].[set_of_page].Members}
SET [~ROWS] AS
{[Date].[Date].Members}
SELECT
NON EMPTY NonEmptyCrossJoin([~COLUMNS_Brand_Brand], NonEmptyCrossJoin([~COLUMNS_Market_Market], [~COLUMNS_set_of_page_set_of_page])) ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [MySQL_Cube]
WHERE [Measures].[NumTransactions];
我使用的是MS SSAS,因此有点不确定是否适用于你,但只是为了帮助我,我将切换到*
运算符进行交叉连接:
WITH
SET [~COLUMNS_Brand_Brand] AS {[Brand].[Brand].[All]}
SET [~COLUMNS_Market_Market] AS
{[Market].[Market].Members}
SET [~COLUMNS_set_of_page segment_set_of_page] AS
{[set_of_page].[set_of_page].Members}
SET [~ROWS] AS
{[Date].[Date].Members}
SELECT
NON EMPTY
[~COLUMNS_Brand_Brand]
*[~COLUMNS_Market_Market]
*[~COLUMNS_set_of_page_set_of_page] ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [MySQL_Cube]
WHERE [Measures].[NumTransactions];
我希望(由于未经测试,我有点不确定所有上下文将被保留),我们可以添加一个自定义的meassure,将当前页面除以前一页以获得百分比:
WITH
SET [~COLUMNS_Brand_Brand] AS {[Brand].[Brand].[All]}
SET [~COLUMNS_Market_Market] AS
{[Market].[Market].Members}
SET [~COLUMNS_set_of_page segment_set_of_page] AS
{[set_of_page].[set_of_page].Members}
SET [~ROWS] AS
{[Date].[Date].Members}
MEMBER [Measures].[NumTransactionsPercent] AS
[set_of_page].CURRENTMEMBER
/ [set_of_page].CURRENTMEMBER.LAG(1)
SELECT
NON EMPTY
[~COLUMNS_Brand_Brand]
*[~COLUMNS_Market_Market]
*[~COLUMNS_set_of_page_set_of_page] ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [MySQL_Cube]
WHERE [Measures].[NumTransactionsPercent]; //[Measures].[NumTransactions];