表格模型。 “历史项目一小时值”表包含多个日期项目工作时间的小时值(如价格)。 它仅连接到项目表,而不连接到日期表。
我正在尝试计算小时数。对于我的问题,可以说每个项目只有一个小时。 我为每个项目都得到了正确的答案,但是总数很大,我不明白。
感谢您的帮助。
One Hour Value On Date :=
VAR OneHourValueOnStartDate =
FILTER (
'Historic Project One Hour Value',
'Historic Project One Hour Value'[HistoricOneHourValueBeginDate]
= DATE ( 2016, 12, 31 )
)
VAR OneHourValueOnStartDateForOneProject =
1
* /*Actually, I multiply the working hours of the project, but this number is correct */
CALCULATE (
SUM ( 'Historic Project One Hour Value'[HistoricOneHourValue] ),
OneHourValueOnStartDate
)
RETURN
IF (
HASONEVALUE ( Projects[Project ID] ),
CALCULATE ( OneHourValueOnStartDateForOneProject ),
CALCULATE (
SUMX ( VALUES ( Hours[HoursProjectID] ), OneHourValueOnStartDateForOneProject )
)
)
答案 0 :(得分:1)
变量OneHourValueOnStartDateForOneProject
是一个常量(不是度量),因此总计发生的是,该值为您提供Project ID
计算部分中所有VAR
值的总和
从这里开始,您的SUMX
将常数值添加的次数与不同的HoursProjectID
相同。
答案 1 :(得分:0)
Alexis Olson回答后的正确代码:
One Hour Value On Date:=
VAR OneHourValueOnStartDate =
FILTER (
'Historic Project One Hour Value',
'Historic Project One Hour Value'[HistoricOneHourValueBeginDate]
= date(2016,12,31)
)
VAR OneHourValueOnStartDateForOneProject =
1 * /*Actually, I multiply the working hours of the project, but this number is correct */
CALCULATE (
SUM( 'Historic Project One Hour Value'[HistoricOneHourValue] ),
OneHourValueOnStartDate
)
RETURN
IF (
HASONEVALUE ( Projects[Project ID] ),
CALCULATE ( OneHourValueOnStartDateForOneProject ),
CALCULATE (
SUMX (
Values ( Hours[HoursProjectID] ),
1
* CALCULATE (
MAX ( 'Historic Project One Hour Value'[HistoricOneHourValue] ),
FILTER (
OneHourValueOnStartDate,
'Historic Project One Hour Value'[HistoricOneHourValueProjectID]
= EARLIER ( 'Hours'[HoursProjectID] )
)
)
)
)
)
谢谢