You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MDX度量值过滤需求:需排除指定度量值组合非零的记录

实现MDX查询中的度量值过滤需求

没问题,我来帮你调整这个MDX查询,实现你要的过滤逻辑——排除[Measures].[Sales Amount] + [Measures].[Outstanding Orders] + [Measures].[Sales Amount] <> 0的记录,也就是只保留这个表达式结果等于0的行。

核心思路

在MDX中,要基于度量值过滤行维度的成员,我们可以使用FILTER()函数包裹行轴上的成员集合,只保留满足指定条件的成员。你的需求等价于保留[Measures].[Sales Amount] + [Measures].[Outstanding Orders] + [Measures].[Sales Amount] = 0的记录,所以我们把这个等式作为过滤条件传入FILTER()。

修改后的MDX查询

SELECT 
  NON EMPTY { 
    [Measures].[Ending Quantity], 
    [Measures].[Average Unit Cost], 
    [Measures].[Cost Amount], 
    [Measures].[Sales Amount], 
    [Measures].[Invoiced Quantity], 
    [Measures].[Outstanding Orders], 
    [Measures].[Average Unit Price] 
  } ON COLUMNS, 
  NON EMPTY FILTER(
    { 
      ( [Item].[Item].[Item].ALLMEMBERS * 
        [Item].[Last GRN Date].[Last GRN Date].ALLMEMBERS * 
        [Item].[Division].[Division].ALLMEMBERS * 
        [Item].[Last Order Number].[Last Order Number].ALLMEMBERS * 
        [Item].[Vendor Item Number].[Vendor Item Number].ALLMEMBERS * 
        [Item].[Unit Cost].[Unit Cost].ALLMEMBERS * 
        [Item].[Current Retail Price].[Current Retail Price].ALLMEMBERS * 
        [Item].[Vendor Name].[Vendor Name].ALLMEMBERS * 
        [Item].[Last In Date].[Last In Date].ALLMEMBERS * 
        [Item].[Last Markdown Date].[Last Markdown Date].ALLMEMBERS * 
        [Item].[Last Markdown Code].[Last Markdown Code].ALLMEMBERS * 
        [Item].[Buyer].[Buyer].ALLMEMBERS * 
        [Item].[Inventoriable].[Inventoriable].ALLMEMBERS * 
        [Item].[Original Retail Price].[Original Retail Price].ALLMEMBERS ) 
    },
    -- 过滤条件:只保留表达式等于0的记录
    [Measures].[Sales Amount] + [Measures].[Outstanding Orders] + [Measures].[Sales Amount] = 0
  ) DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_VALUE, MEMBER_UNIQUE_NAME ON ROWS 
FROM ( 
  SELECT ( { [Item].[Division].&[1000], [Item].[Division].&[2000], [Item].[Division].&[3000], [Item].[Division].&[4000], [Item].[Division].&[5000], [Item].[Division].&[6000], [Item].[Division].&[7000], [Item].[Division].&[8000], [Item].[Division].&[9000] } ) ON COLUMNS 
  FROM ( 
    SELECT ( { [Item].[Buyer].&[SHARAN], [Item].[Buyer].&[ALISHA], [Item].[Buyer].&[NORMAN], [Item].[Buyer].&[MARISA] } ) ON COLUMNS 
    FROM ( 
      SELECT ({ [Item].[Inventoriable].&[Inventoriable] }) ON COLUMNS 
      FROM [Sales Purchases and Stock] 
    ) 
  ) 
) 
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS;

关键点说明

  • FILTER()函数的第一个参数是你原本的行维度成员笛卡尔积集合,第二个参数是过滤条件;
  • 我注意到你原条件里写了两次[Measures].[Sales Amount],如果是笔误的话,可以根据实际需求调整表达式(比如改成[Measures].[Sales Amount] + [Measures].[Outstanding Orders] + [Measures].[另一个度量值]);
  • 保留了原查询中的NON EMPTY,可以进一步过滤掉所有度量值都为空的行,提升查询效率。

内容的提问来源于stack exchange,提问作者Heike Holton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:45:03