0

我正在学习 MDX,我有一个问题要创建一个百分比。基本上,我从 Google Analytics API 中为多组页面提取数据。对于每组,我提取了 UniquePageviews 的数量。

SQL 列如下所示:

  • 日期
  • 设备类别
  • 中等的
  • 独特的综合浏览量
  • 交易
  • set_of_page (行包含页面集的名称。为了简化:1. First, 2. Second, 3. Third )
  • 品牌(品牌A、品牌B)
  • 市场(市场 X,市场 Y)

这是我目前的观点: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]

非常感谢!

4

1 回答 1

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];

我希望(因为未经测试,我有点不确定所有上下文都会被保留)我们可以添加一个自定义度量,将当前页面除以前一个页面以获得百分比:

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];
于 2016-04-30T09:15:24.187 回答