Google SpreadSheet - handling MM:SS.sss time formats - time

I'd like to process the following columns in a google-spreadsheet. The Time column represents the minutes, second and milliseconds take to run 1km and I'd like to be able to sum the four values.
Split Time
1 3:13:4
2 3:20:5
3 3:16:1
4 3:26:3
I suspect that I need to convert and split the time column into a specific minute and second columns to achieve this goal but would appreciate any advise that the developer may have.
I updated the format of the time column and used the SPLIT / CONTINUE functions
Minutes=SPLIT(B2,":")
Seconds=CONTINUE(C2,1,2)
Total Seconds=(C2*60)+D2
The table now looks like
Split Time minutes Seconds Total Seconds
1 03:13:00 3 13 193
2 03:15:00 3 15 195
3 03:16:00 3 16 196
Still wondering about the most efficient way to convert the Total Seconds value to time.

You can use the LEFT(text, number), MID(text, start, number), and RIGHT(text, number).
In detail:
Minutes = LEFT(B2, 1)
Seconds = MID(B2, 3, 2)
Milliseconds = RIGHT(B2, 2)

You can just use SUM for those values, a la:
=SUM(A1:A4)
Alternatively, you can use functions such as HOUR, MINUTE and SECOND to extract appropriate values if you want more fine-grained control.

Where the source data is a specified (ie The Time column represents the minutes,second and milli seconds) then to be able to add to a sensible result (795.013 seconds for the first sample of four) conversion similar to:
=60*index(split(B2,":"),0,1)+index(split(B2,":"),0,2)+index(split(B2,":"),0,3)/1000
is required.
To convert the total (assumed to be in C6) to the same absurd format as for input (13:15:13):
=int(C6/60)&":"&int(mod(C6,60))&":"&value(mid(C6,find(".",C6)+1,3))
`

In your original sheet, in a new column:
=TO_DATE("00:0" & left($B2,4))
Then copy the formula down the column.
This will convert your M:SS (the left 4 characters of your data) to the sheet's system date/time format, for each entry in column B.
You can then sum and format the results as you like.
This assumes there are no leading zeroes on your data. You can add code to check for this, but if your times all have single digits for the minutes value, it won't matter.

Related

Spotfire Calculation using previous rows calculated data

I have been struggling with the following calculation. I have tried a few previous, next and overs but I cant seem to get the syntax correct.
Basically i need to subtract demand from stock on hand, to get a new column. the the next row will use the newly created column as stock on hand and the subtract the demand for that row, then that result becomes the new stock on hand etc. i cant get it to loop. I have ranked the demand in order of date required per plant. AS the data set will have multiple Plants, SOH and demand.
The attached pic shows A020 only has one QTY short so that is straight forward, but for A030 opening SOH is 152, and the 1st date QTY short is 12, so i need 152-12 = 140. then the second date QTY which is ranked 2, needs to be 140 - 12 = 128, so then rank 3 uses 128 - 12 and so on. ie the SOH needs to dynamically update.
data set
It might not be natively possible in point-and-click Spotfire (happy to be corrected if this is incorrect).
You should consider writing a data function using R to do this groupby-loop operation.

Using Power BI Desktop, how can I present Time Duration in a matrix that converts it to decimal?

I have Begin Date and End Date in my data file (Excel), then in PowerQuery I add a column where I simply subtract the Begin Date from End Date to create a new column "Import Time", change the result's data type to Duration and in PowerQuery, the column correctly shows the difference expressed in Day:Hour:Minute:Seconds. However, in a report, I need to show the average not of an entire column, but of groups of values in a matrix based on the entire table. In other words, I'm looking for a table that shows columns for Category Name, Avg. Duration and Max Duration, with rows showing the results for each unique Category.
The problem is that when I drag a table field in to the Visualizations Value area and change to Average, it expresses the result as a decimal, and I can't figure out how to show the date / time equivalent. I thought I might have to multiply by 3,600 since the result might be shown in milliseconds, but that didn't work. Any thoughts?
So I theorized that perhaps the issue wasn't one with Power BI, but perhaps with how Microsoft expresses date / time computations. I edited my Excel file that contains the source data and computed the "Import Time" by subtracting Begin Time from End Time. By default, it displays in date / time format of "hh:mm:ss.0000". I then asked Google and came across a simple explanation: to express a date / time in numeric format, you need to multiply the date / time by 24 (hours), 60 (minutes) and 60 (seconds) if that's how you wanted to express the result. I then created a Pivot Table summarizing the average of the Import Times and saw the same thing I did in my Power BI report, which is when it clicked it for me.
To solve the issue, I edited my Power Query step to compute the import time and included " * 24 * 60 * 60" in the formula. After updating the report, the results matched what I saw in Excel and I'm good. Hopefully this helps others to deal with this vexing issue.
You wrap your averaging measure in a FORMAT function to convert it to precisely the text format you want to show in your matrix. For example, suppose your raw output is
Group AvgDuration
------------------
A 0.0633
B 0.2733
C 0.0600
These numbers are in the unit of days, so you can convert to hours, minutes, or seconds like this e.g.:
FORMAT ( [AvgDuration] * 24, "0.00h" )
FORMAT ( [AvgDuration] * 24 * 60, "#,0m" )
FORMAT ( [AvgDuration] * 24,* 60 * 60, "#,0s" )
FORMAT ( [AvgDuration], "hh:mm:ss" )
(where [AvgDuration] is your measure you use to calculate the average)
Those last two should look like this:
Group AvgDuration
------------------
A 5,472s
B 23,616s
C 5,184s
and
Group AvgDuration
------------------
A 01:31:12
B 06:33:36
C 01:26:24

Select first and last element on a column (time format) gnuplot

I am performing statistics with Gnuplot on several files, each with a large numbers of rows and columns, first of them in time format "%H:%M:%S". I've found here (sorry, cannot find the link) a way to easily do the process, that is:
# converts the time string in column COL to a number of seconds
intime(COL) = strptime("%H:%M:%S",strcol(1))
# finds correlation of time (seconds) in col 1 with the value in col 2
startrange0 = strptime("%H:%M:%S","18:46:27")
endrange0 = strptime("%H:%M:%S","23:59:27")
stats [startrange0:endrange0] 'datafile.txt' u (intime(1)):2 prefix "A"
set print outfilename append
My problem here is that I have to access to each file to write the starting and ending time exactly in the code, wich breaks a bit the automation of the script.
The question is, is there a way to access the first and last element of the time column (that is, the "18:46:27" and the "23:59:27" in the example), so it can read it form each file?
Thanks!

Openedge syntax for TIME minus 4 hours

I am trying to figure out how to write a Openedge query where i can look back 4 hours. i have struggled with the TIME syntax before. If i understand correctly, the TIME representation in Openedge is in seconds starting from midnight. The query i am trying to write would run 4 times a day, looking back 4 hours.
Is there any way to do this using TIME? Maybe i have to write 4 different queries that only pull records starting at a specific time?
Thanks very much for any help i can get, it is greatly appreciated!
Martin
You don't describe the contents or layout of the table very well.
Yes, TIME, in Progress ABL contains the number of seconds since midnight. So 16:20 for instance is 58800 (16 * 3600 + 20 * 60).
Assuming the field in your table contains an integer representing the time you can do like this to select the records that was created up to four hours ago:
DEFINE VARIABLE iTime AS INTEGER NO-UNDO.
/* I find it easier to write like this but you can very well do = TIME - 14400 instead */
iTime = TIME - 4 * 3600.
FOR EACH tablename NO-LOCK WHERE tablename.createtime >= iTime:
/* Do something */
END.
Note: perhaps you need to check create date as well? And handle midnight?
Another option might be to look at the DATETIME type. There you can do operations like adding and distracting an amount of time.
DEFINE VARIABLE datnow AS DATETIME NO-UNDO.
DEFINE VARIABLE datthen AS DATETIME NO-UNDO.
datnow = NOW.
DISPLAY datnow.
datthen = ADD-INTERVAL(datnow, -4, "hours").
DISPLAY datthen.

Duration format in google spreadsheet

I'm trying to apply a duration format to some cells in google spreadsheet. I would like to convert an integer number in a format: X days x hours x minutes.
I've tried with some formats like: d:h:mm but i found a problem when I apply the format. It always put one day less. When I write 1 in the cell the convert to 31:0:00. When I write 2 the cells changes to 1:00:00.
That is because the duration format is actually a date / time format (for comparing dates).
If you simply enter a number (1) google will interpret that as midnight (as times are stored as fractions of whole days) of the reference day number 1.
Reference day in Google Sheets is 31/12/1899 - IE the 31st day of the month. That is why your result returns days=31.
To achieve what you want you effectively want to add 1 to your values. so that 1 (+1) actually becomes "2 days since 31/12/1899 - ie 01/01/1900 - ie 1 day, and you could then use custom format for display, but this wont work when you have >31 days.
I think the best way is to simply concatenate the data you have with relavent parts like so (where A1 is a cell containg your data - 1,2,1.5 etc):
=int(A1)&" days "&int(MOD(A1,1)*24)&" hours " & mod(MOD(A1,1)*24,1)*60 & " minutes"

Resources