首页 文章

DAX [SSAS表格] DISTINCTCOUNT与lastnonempty日期

提问于
浏览
1

我正在分析产品分销数据 . 我们想要市场渗透率[深度]的快照测量 .

Depth := DIVIDE (
   [Count of ranged product/store distribution points],
   [Count of audited product/store distribution points]
)

我有2个表:'分配'(经审计的分发点);和'日历'(日期表) . 它们与模型有关 .

对于2015年6月30日的快照,我不想在11月15日之前添加新产品/商店,但我确实希望包含在之前3个月内审核过的任何数据点 .

从逻辑上讲,分子是分母的过滤子集,所以我首先需要分母,这就是我被困住的地方 .

如果我只是做一个基本的distinctcount没有任何花哨的代码我得到这个 .

  • 月,分母

  • 3月15日,1

  • 4月15日,0

  • 5月15日,0

  • 6月15日,2

  • 7月15日,6日

  • 8月15日,5

  • 9月15日,1

  • 10月15日,40

  • Nov-15,53

  • Dec-15,92

但我想要一些看起来像这样的东西:

  • 月,分母

  • 3月15日,150

  • 4月15日,150

  • 5月15日,150

  • Jun-15,170 - 在20家商店中添加1个新产品

  • 1970年7月15日

  • Aug-15,170

  • 9月15日,170

  • 10月15日,200 - 在30家商店中添加1个新产品

  • Nov-15,200

  • Dec-15,200

我需要在分发[日期]上删除过滤器上下文并对分布分布[日期] <=日历[日期]应用过滤器,然后执行非重复计数但我得到错误 .

Count of audited product/store distribution points:=
CALCULATE(
   COUNTROWS ( 
      VALUES ( Distribution[ProductStoreKey])
   ), 
   NOT ( Distribution[Status On Exit] = "Ineligible" ),
   FILTER (
      ALL ( Distribution[Date] ),
      Distribution[Date] <= Calendar[Date]
   )   
)

ERROR:
The value for column 'Date' in table 'Distribution' cannot be determined in 
the current context. Check that all columns referenced in the calculation  
expression exist, and that there are no circular dependencies. This can also 
occur when the formula for a measure refers directly to a column without 
performing any aggregation--such as sum, average, or count--on that column. 
The column does not have a single value; it has many values, one for each 
row of the table, and no row has been specified.

它可能是使用HASONEVAUE的过滤器的防错 . 我不确定 .

在其他想法中,我尝试重写过滤器,但这也不起作用 .

FILTER (
     Distribution,
     Distribution[Date] <= 
        CALCULATE (
           MAX(Distribution[Date]),
           Distribution[Date]<=Calendar[Date] 
        )
  )

Error:
The expression contains multiple columns, but only a single column can be 
used in a True/False expression that is used as a table filter expression.

此代码获取变量Calendar [Date]的最后一个数据点的DistibutionDate,但我无法弄清楚如何合并它 .

Last Ever Dist Date:=    
CALCULATE ( 
   LASTDATE( Distribution[DATE] ), 
   DATESBETWEEN(
      Calendar[date],
      BLANK(),
      LASTDATE(Calendar[Date])
   ),
   ALL(Calendar)
)

1 回答

  • 0

    怎么样:

    Count of audited product/store distribution points:=
    CALCULATE(
       DISTINCTCOUNT(Distribution[ProductStoreKey]),
       DATESBETWEEN(
          Calendar[date],
          BLANK(),
          LASTDATE(Calendar[Date])
       ),
       ALL(Calendar)
    )
    

相关问题