DAX [SSAS 表格] DISTINCTCOUNT with lastnonempty date
DAX [SSAS Tabular] DISTINCTCOUNT with lastnonempty date
我正在分析产品分布数据。
我们想要市场渗透[深度]的快照测量。
Depth := DIVIDE (
[Count of ranged product/store distribution points],
[Count of audited product/store distribution points]
)
我有 2 个 table:
'Distribution'(审核分配点);和
'Calendar'(日期 table)。
它们在模型中是相关的。
对于 2015 年 6 月 30 日的快照,我不想包含 11 月 15 日的新 product/stores,但我确实希望包含前 3 个月审计的任何数据点。
从逻辑上讲,分子是分母的过滤子集,所以我首先需要分母,这就是我遇到的问题。
如果我只是做一个基本的 distinctcount 而没有任何花哨的代码,我就会得到这个。
- 月份,分母
- 3 月 15 日,1
- 4 月 15 日,0
- 5 月 15 日,0
- 2 月 15 日
- 6 月 15 日
- 8 月 15 日,5
- 9 月 15 日,1
- 10 月 15 日,40
- 11 月 15 日,53
- 92 年 12 月 15 日
但我想要这样的东西:
- 月份,分母
- 3 月 15 日,150
- 4 月 15 日,150
- 5 月 15 日,150
- 170 年 6 月 15 日 -- 在 20 家商店中添加 1 种新产品
- 170 年 7 月 15 日
- 170 年 8 月 15 日
- 170 年 9 月 15 日
- 200 年 10 月 15 日 -- 在 30 家商店中添加 1 个新产品
- 200 年 11 月 15 日
- 200 年 12 月 15 日
我需要删除 Distribution[Date] 上的过滤器上下文并在 Distribution[Date] <= Calendar[Date] 上应用过滤器,然后进行非重复计数,但出现错误。
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)
)
怎么样:
Count of audited product/store distribution points:=
CALCULATE(
DISTINCTCOUNT(Distribution[ProductStoreKey]),
DATESBETWEEN(
Calendar[date],
BLANK(),
LASTDATE(Calendar[Date])
),
ALL(Calendar)
)
我正在分析产品分布数据。 我们想要市场渗透[深度]的快照测量。
Depth := DIVIDE (
[Count of ranged product/store distribution points],
[Count of audited product/store distribution points]
)
我有 2 个 table: 'Distribution'(审核分配点);和 'Calendar'(日期 table)。 它们在模型中是相关的。
对于 2015 年 6 月 30 日的快照,我不想包含 11 月 15 日的新 product/stores,但我确实希望包含前 3 个月审计的任何数据点。
从逻辑上讲,分子是分母的过滤子集,所以我首先需要分母,这就是我遇到的问题。
如果我只是做一个基本的 distinctcount 而没有任何花哨的代码,我就会得到这个。
- 月份,分母
- 3 月 15 日,1
- 4 月 15 日,0
- 5 月 15 日,0
- 2 月 15 日
- 6 月 15 日
- 8 月 15 日,5
- 9 月 15 日,1
- 10 月 15 日,40
- 11 月 15 日,53
- 92 年 12 月 15 日
但我想要这样的东西:
- 月份,分母
- 3 月 15 日,150
- 4 月 15 日,150
- 5 月 15 日,150
- 170 年 6 月 15 日 -- 在 20 家商店中添加 1 种新产品
- 170 年 7 月 15 日
- 170 年 8 月 15 日
- 170 年 9 月 15 日
- 200 年 10 月 15 日 -- 在 30 家商店中添加 1 个新产品
- 200 年 11 月 15 日
- 200 年 12 月 15 日
我需要删除 Distribution[Date] 上的过滤器上下文并在 Distribution[Date] <= Calendar[Date] 上应用过滤器,然后进行非重复计数,但出现错误。
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)
)
怎么样:
Count of audited product/store distribution points:=
CALCULATE(
DISTINCTCOUNT(Distribution[ProductStoreKey]),
DATESBETWEEN(
Calendar[date],
BLANK(),
LASTDATE(Calendar[Date])
),
ALL(Calendar)
)