可以建议您创建另一个包含不同值的表(我假设唯一的组合是Date <-> Subject
)
下面的脚本将创建OverallDuration
表,其中包含组合的不同持续时间值Date <-> Subject
。这样,您将拥有一个OverallDuration
可在 KPI 中使用的附加字段。
OverallDuration
表格链接到RawData
表格(它本身链接到表格),这Calendar
意味着OverallDuration
计算将尊重Subject
,LessonYear
等上的选择LessonMonth
(请看Math
下面的选择图片)
RawData:
Load
*,
// Create a key field with the combination of Date and Subject
Date & '_' & Subject as DateSubject_Key
;
Load * Inline [
Date, Duration, Subject, Attendee
1/10/2019, 2:00, Math, Joe Bloggs
1/10/2019, 2:00, Math, John Doe
2/10/2019, 3:00, English, Jane Doe
6/11/2019, 1:00, Geog, Jane Roe
17/12/2019, 0:30, History, Joe Coggs
];
// Load distinct DateSubject_Key and the Duration
// converting the duraion to time.
// This table will link to RawData on the key field
OverallDuration:
Load
Distinct
DateSubject_Key,
time(Duration) as OverallDuration
Resident
RawData
;
// Creating calendar table from the dates (distinct)
// from RawData and creating two additional fields - Month and Year
// This table will link to RawData on Date field
Calendar:
Load
Distinct
Date,
Month(Date) as LessonMonth,
Year(Date) as LessonYear
Resident
RawData
;
重新加载上面的脚本后,您的表达式将只是sum( OverallDuration )
您可以在下面的数据透视表中看到结果:
总持续时间为06:30
小时,持续时间Math
为02:00
小时:
您的数据模型将如下所示:
我喜欢将我的日历数据保存在单独的表中,但如果需要,您可以将月份和年份字段添加到主表中