【问题标题】:how to make sub total and grand total blank using DAX in tabular model?如何在表格模型中使用 DAX 制作小计和总计空白?
【发布时间】:2015-10-07 20:36:59
【问题描述】:
12 Month Qty:=CALCULATE ( 
     [Qty],
   DATESINPERIOD ( 
       Calendar[Date] , 
       MAX(Calendar[Date]),
       -12, Month
   ) 
)

目前我有这个公式用于我的测量。 但是,我想让所有小计和毕业生总计为空白。因此我需要正确放置 ISFILTERED 功能。我用 if(ISFILTERED()) 包装了公式,但效果不佳。那么如何正确实现 ISFILTERED 功能呢?或者如果我必须使用不同的公式,我应该在这种情况下使用什么公式?

【问题讨论】:

  • 什么效果不好?你期待看到什么?你究竟看到了什么?屏幕截图或示例工作簿很有帮助。模型图有助于理解您的结构。您使用 ISFILTERED() 测试了哪个字段?
  • adsd:=IF (ISFILTERED ([Local]) && NOT (ISFILTERED ([Local])), CALCULATE ([Local], DATESINPERIOD (Calendar[Date], MAX (Calendar[Date]) , -12, 月 ) ) )
  • 感谢您的回答。它给了我错误列 'local' cannot be found or may not be used in this expression, 因为 local 是一种度量。你有什么办法解决这个问题吗?

标签: dax tabular


【解决方案1】:

根据您对原始问题的 cmets:

ISFILTERED() 必须将列作为其参数,而不是度量。 ISFILTERED() 将告诉您是否已将过滤器(通过数据透视表行、列、过滤器或切片器)应用于模型中的特定列。因此,您可以使用它来抑制对层次结构某些级别的度量的评估。

假设您有一个度量,当您处于类别>子类别>项目的层次结构的子类别级别时要显示为空白:

IF(
    ISFILTERED(<table>[SubCategory])
    ,BLANK()
    ,[Measure]
)

这将在 [SubCategory] ​​列应用了过滤器的任何地方返回空白。

编辑评论:

您想要空白的层次结构的哪个级别是 ISFILTERED() 中要引用的列。

我通常会将此模式与日期层次结构一起使用来显示不同级别的聚合,并且我倾向于使用 HASONEVALUE() 作为我的测试。我将在 SWITCH() 函数中应用一系列这些测试。 SWITCH() 只是嵌套 IF() 的语法糖 - 如果需要参考,可以查找它。

因此:

MyConditionalMeasure:=
SWITCH( TRUE()
    ,HASONEVALUE(DimDate[Date] 
        // This means we're at the date level of the hierarchy
    ,[BaseMeasure] // The measure to evaluate at that first level
    ,HASONEVALUE(DimDate[Month]) 
        // This is true for a month or a date only, but we've
        // already captured the date possibility above
    ,[Month-appropriate Aggregation of BaseMeasure]
    ,HASONEVALUE(DimDate[Year])
        // Again, true for a single date or a single month, but
        // we've already covered those, so the year level is all
        // that's left
    ,[Year-appropriate Aggregation of BaseMeasure]
    ,BLANK() // The last argument is taken as a final ELSE
        // condition, capturing anything we didn't cover above,
        // which would include the grand total - this will blank the
        // grand total, or e.g. DimDate[Decade] since that is a
        // coarser granularity than we covered with our tests above

【讨论】:

  • 我将其用于层次结构,所以我是否将父列放在那里?如果我也想在总计行上留空怎么办?
  • Asdasdasdaasd := SWITCH (TRUE (), HASONEVALUE ([level04]), CALCULATE ([Local], DATESINPERIOD (Calendar[Date], MAX (Calendar[Date]), -12, MONTH) , HASONEVALUE ([level03] ), CALCULATE ([Local], DATESINPERIOD ( Calendar[Date], MAX ( Calendar[Date] ), -12, MONTH ), HASONEVALUE ([level02] ), BLANK () ) ) )跨度>
  • 感谢您的支持!我试过这样,但它给了我错误“真/假表达式没有指定一列”。如何添加 True/False 表达式?
  • 您没有在适当的时候关闭 CALCULATE()。第一个 DATESINPERIOD() 之后的所有内容都包含在第一个 CALCULATE() 中
  • 谢谢!正确关闭我的计算后它可以工作!
猜你喜欢
  • 1970-01-01
  • 2019-01-18
  • 1970-01-01
  • 1970-01-01
  • 2017-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-08
相关资源
最近更新 更多