【问题标题】:MDX query with count distinct filtered on another measure, that plays with other filters在另一个度量上过滤计数不同的 MDX 查询,与其他过滤器一起使用
【发布时间】:2015-09-12 00:14:09
【问题描述】:

在 SSAS AdventureWorks 架构中,我试图计算出有多少不同客户的互联网订单超过 1000 美元。

我试图进行这样的 MDX 查询,它似乎几乎工作,除了新措施似乎忽略了切片器轴/WHERE 条件,显示了客户的数量所有个国家,不只是澳大利亚:

With 
member [measures].[DistinctCustomersHighSales] as 
distinctcount(
   filter([Customer].[Full Name].Members, [Measures].[Internet Sales-Sales Amount] > 1000)
)
SELECT {
   [Measures].[Internet Sales-Sales Amount],
   [Measures].[DistinctCustomersHighSales]
    }
 on columns,
([Date].[Calendar Date].[Calendar Year].Members) on rows
FROM [Analysis Services Tutorial]
WHERE [Customer].[Customer Geography].[Country-Region].[Australia]

我做错了什么?

如果我在 SQL 中执行此操作,我会寻找类似的东西

 SELECT Year(OrderDate) as year,
     sum(SalesAmount) 
     count(case when count(distinct case when SalesAmount > 1000 then dc.customerkey end)
 FROM dbo.FactInternetSales  fis
    join dbo.dimcustomer dc on fis.CustomerKey=dc.CustomerKey
    join dbo.DimGeography  dg on dc.GeographyKey=dg.GeographyKey
 WHERE EnglishCountryRegionName='Australia'
 GROUP BY year(OrderDate)
 ORDER BY year

【问题讨论】:

    标签: ssas mdx


    【解决方案1】:

    尝试添加EXISTING:

    With 
    member [measures].[DistinctCustomersHighSales] as 
    distinctcount(
       filter(EXISTING [Customer].[Full Name].Members, [Measures].[Internet Sales-Sales Amount] > 1000)
    )
    SELECT {
       [Measures].[Internet Sales-Sales Amount],
       [Measures].[DistinctCustomersHighSales]
        }
     on columns,
    ([Date].[Calendar Date].[Calendar Year].Members) on rows
    FROM [Analysis Services Tutorial]
    WHERE [Customer].[Customer Geography].[Country-Region].[Australia]
    

    作用域是 MDX 中一个非常重要的概念。只有添加EXISTING,引擎才会实现切片器。

    成员定义中的初始集合是:

    [Customer].[Full Name].Members
    

    集合在 MDX 中是静态的。因此,默认情况下,此集合包含所有客户。添加EXISTING 时,在形成集合之前,会检查上下文。根据您的多维数据集中的维度使用(关系),它能够过滤属于澳大利亚的客户。这样就可以了。

    【讨论】:

    • 这似乎奏效了。我还是不明白为什么
    • @wrschneider 添加信息
    • 大坝——打败我!!! ...EXISTING 将当前上下文拉入 WITH 子句
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    相关资源
    最近更新 更多