我有一个客户维度:
Dimcust
| Custnum | StartDate | EndDate |
我想使用DAX创建一个新表,去年每周计算每周的客户数量(不同的custnum)(意味着startdate< week和enddate为null或enddate>周)。
但是我不能让它工作。
我尝试的是以下内容:
Active Users = Calculate(COUNTROWS(filter(DimCustomer; DimCustomer[StartDate].[Date] > WeeklyKPI[Date];DimCustomer[StartDate].[Date] < WeeklyKPI[Date])))
这给出了错误:
A single value for column 'Date' in table 'WeeklyKPI' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
其中WeeklyKPI [Date]是一个日期表,每个日期都在我想要的范围内。如果这样做了,我会做同样的事情,只用周数。
我想要的是什么:
Weeknumber | Number of customers
1 13,430
2 32,530
答案 0 :(得分:0)
您看到错误是因为您尝试将各个值(DimCustomer[StartDate].[Date]
)与多个(WeeklyKPI[Date]
)进行比较。
如果WeeklyKPI[Date]
包含所选周的所有日期,您可以将度量更改为以下内容:
Active Users = Calculate(COUNTROWS(filter(DimCustomer;
DimCustomer[StartDate].[Date] > MIN(WeeklyKPI[Date]);
DimCustomer[StartDate].[Date] < MAX(WeeklyKPI[Date]))))
另一种选择是创建一个包含周数WeekNum(Num)
的表,并允许用户选择单个值。您的衡量标准将变为
Active Users = Calculate(COUNTROWS(filter(DimCustomer;
WEEKNUM(DimCustomer[StartDate].[Date], 2) = FIRSTNONBLANK(WeekNum[Num]))))