问题
I am a beginner for Spotfire. I have a problem about the average calculation per each 15 mins by calculated column. A sample table could be like this:
id time-stamp value
1 7/1/2016 12:01:01 AM 1.1
2 7/1/2016 12:05:03 AM 0.9
3 7/1/2016 12:08:04 AM 1.2
4 7/1/2016 12:09:06 AM 0.8
5 7/1/2016 12:12:09 AM 0.4
6 7/1/2016 12:14:10 AM 0.6
7 7/1/2016 12:15:12 AM 1.3
8 7/1/2016 12:18:04 AM 1.4
9 7/1/2016 12:21:06 AM 0.7
10 7/1/2016 12:24:09 AM 1.7
11 7/1/2016 12:31:10 AM 0.5
12 7/1/2016 12:39:12 AM 1.3
I want to calculate the avg value for each 15 mins, the table is already ordered by time.
the final table I want to have is:
time-stamp Avg
7/1/2016 12:00:00 AM 0.83333
7/1/2016 12:15:00 AM 1.275
7/1/2016 12:30:00 AM 0.9
for example, for the first number 0.83333 =(1.1+0.9+1.2+0.8+0.4+0.6)/6
it seems that I should identify an expression of the calculation for a new table, but how to calculate the avg. for each 15 mins. somebody could help me ?
thanks for your help :)
note: thanks for code @ksp585, but after this, i still have a small problem for it, the cross table just shows the times-stamp until 9:45 PM
回答1:
@ ZAWD - I have created a calculated column which groups the timestamp into 4 quarters for an hour. Used this column in the cross table below to calculate average time.
timestamp grouping expression (time_interval):
case
when (DatePart("minute",[time-stamp])>0) and (DatePart("minute",[time-stamp])<15) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":00" & ":00"
when (DatePart("minute",[time-stamp])=15) and (DatePart("second",[time-stamp])>0) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":15" & ":00"
when (DatePart("minute",[time-stamp])>15) and (DatePart("minute",[time-stamp])<30) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":15" & ":00"
when (DatePart("minute",[time-stamp])=30) and (DatePart("second",[time-stamp])>0) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":30" & ":00"
when (DatePart("minute",[time-stamp])>30) and (DatePart("minute",[time-stamp])<45) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":30" & ":00"
when (DatePart("minute",[time-stamp])=45) and (DatePart("second",[time-stamp])>0) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":45" & ":00"
when (DatePart("minute",[time-stamp])>45) and (DatePart("minute",[time-stamp])<=60) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":45" & ":00"
when (DatePart("minute",[time-stamp])=0) and (DatePart("second",[time-stamp])>0) then Date([time-stamp]) & " " & Hour([time-stamp]) & ":00" & ":00"
else null end
Final Table:
Tested with a different datetime format:
来源:https://stackoverflow.com/questions/39333263/sporfire-calculate-the-avg-per-15-minutes