timmyspan
timmyspan

Reputation: 77

Spotfire AVG value per hour

I have users that have random values per hour across 24 hours. I want to get their average value per hour as it increases. Such as: a value of 3 at 3pm, then 4 at 4pm, 5 at 5pm, find the average per hour and give the total average once there are no more timestamps.

I've tried this:

case  
when (DatePart("hour",[AUDIT_TSP])>0) and (DatePart("hour",[AUDIT_TSP])<1) 
then Date([AUDIT_TSP]) & " " & ":00" & ":00" & Second([AUDIT_TSP]) 
when (DatePart("hour",[AUDIT_TSP])=1) and (DatePart("minute", 
[AUDIT_TSP])>0) then Date([AUDIT_TSP]) & " " & ":01" & ":00" & 
Second([AUDIT_TSP]) 
else null end

This was based off of sporfire: calculate the avg per 15 minutes and I tweaked it for my use but couldn't get the code to show the avg hour and not 15min avg. So I figured to ask here.

My AUDIT_TSP is formatted with DateTime and example values look like:

4/15/2019 6:16:59 AM
4/15/2019 6:20:05 AM

The values are just shipments so, 1 shipment an hour, 2 shipments an hour, etc. Just trying to get the average per hour.

enter image description here

I don't expect the average per hour to show up on the timeline, the values it's showing here is the amount of shipments for each hour. If the average can be shown on the timeline, then great, if not, then I can audible and show it in a textbox if that's possible as well.

Upvotes: 0

Views: 661

Answers (1)

Gaia Paolini
Gaia Paolini

Reputation: 1492

You could produce an intermediate column to mark each hour with

[hourBin] calculated as: Integer(ToEpochSeconds([time-stamp]) / 3600)

Here [time-stamp] is your timestamp column. ToEpochSeconds(..) counts the number of seconds from a reference date (usually 1st Jan 1970). When you divide it by 3600 and take the integer part, you get an hour counter.

Then average your values for each hour

Avg([value]) OVER ([hourBin])

And/or visualise the average and the spread around it in a box-plot of [value] with [hourBin] as the category.

If you want the intermediate column to look more meaningful you can rescale it by its first value so it starts from 0 (or add any number you wish):

Integer(ToEpochSeconds([time-stamp]) / 3600) - Min(Integer(ToEpochSeconds([time-stamp]) / 3600))

Upvotes: 1

Related Questions