cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-488599%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3EBerechnen%20Sie%20die%20Zeitdifferenz%20und%20summieren%20Sie%20die%20Werte%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-488599%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3EIch%20habe%20eine%20Tabelle%20mit%20einer%20Zeitspalte%20in%20diesem%20Format%3A%20m%2Fd%2Fyh%3Am%3As%3C%2FP%3E%3CP%3EIch%20m%C3%B6chte%20eine%20neue%20Spalte%20mit%20dem%20Namen%20%E2%80%9ECumTimeSec%E2%80%9C%20erstellen%2C%20die%20die%20kumulative%20Zeitdifferenz%20bis%20zu%20dieser%20Zeile%20anzeigt.%3C%2FP%3E%3CP%3EZum%20Beispiel%2C%3C%2FP%3E%3CP%3EZeit%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CTABLE%20border%3D%221%22%3E%3CTBODY%3E%3CTR%3E%3CTD%3EZeit%3C%2FTD%3E%3CTD%3ECumTimeSec%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%3CP%3E11.05.2022%2017%3A30%3A03%20Uhr%3C%2FP%3E%3C%2FTD%3E%3CTD%3E0%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%3CP%3E11.05.2022%2017%3A30%3A08%20Uhr%3C%2FP%3E%3C%2FTD%3E%3CTD%3E5%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E11.05.2022%2017%3A30%3A20%20Uhr%3C%2FTD%3E%3CTD%3E17%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E11.05.2022%2017%3A30%3A23%20Uhr%3C%2FTD%3E%3CTD%3E20%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%20%3C%2FP%3E%3CP%3EIch%20dachte%2C%20ich%20k%C3%B6nnte%20diesen%20Code%20verwenden%2C%20um%20die%20Differenz%20zwischen%20den%20einzelnen%20Zeilen%20zu%20berechnen%2C%20bin%20mir%20aber%20nicht%20sicher%2C%20wie%20ich%20die%20Werte%20summieren%20soll%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%26lt%3B%26lt%3B%20New%20Column(%20%22CumTimeSec%22%2C%0A%09Numeric%2C%0A%09%22Continuous%22%2C%0A%09formula(%20%20%3ATime%20-%20Lag(%20%3ATime)%20)%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-488599%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CLINGO-LABEL%3EMassenanpassung%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-488707%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Zeitdifferenz%20berechnen%20und%20Werte%20aufsummieren%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-488707%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EVielen%20Dank%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1643%22%20target%3D%22_blank%22%3E%20%40_jr%3C%2FA%3E%20!!%20Lief%20wie%20am%20Schn%C3%BCrchen!!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-488693%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Zeitdifferenz%20berechnen%20und%20Werte%20aufsummieren%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-488693%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIch%20habe%20Dif%20noch%20nie%20verwendet%2C%20aber%20Sie%20k%C3%B6nnten%20es%20mit%20Col%20Cumulative%20Sum%20kombinieren%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ECol%20Cumulative%20Sum(Dif(%3ATime))%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-488626%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20Zeitdifferenz%20berechnen%20und%20Werte%20aufsummieren%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-488626%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHallo%20Lavik17%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EVerz%C3%B6gerung%20ist%20f%C3%BCr%20diese%20Anwendung%20n%C3%BCtzlich%2C%20aber%20Sie%20m%C3%BCssen%20sie%20ein%20paar%20Mal%20verwenden.Beachten%20Sie%2C%20dass%20Dif()%20die%20Differenz%20zwischen%20der%20aktuellen%20Zeile%20und%20einer%20%22Lag%22-Zeile%20nimmt.Zum%20Beispiel%20berechnen%20Sie%20oben%20%3ATime%20-%20Lag(%3ATime).Das%20ist%20dasselbe%20wie%20Dif(%3ATime).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHier%20ist%20ein%20Beispiel%2C%20das%20Sie%20mit%20JMP-Beispieldaten%20ausf%C3%BChren%20k%C3%B6nnen.Die%20Tabelle%20listet%20nur%20eine%20Folge%20von%20Jahren%20auf%2C%20funktioniert%20aber%20genauso%20f%C3%BCr%20eine%20Zeitspalte.%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%3D%20Open(%22%24SAMPLE_DATA%2FTime%20Series%2FSeriesQ.jmp%22)%3B%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22CumTimeYear%22%2C%20Formula(%0A%20If(%20Row()%20%26gt%3B%201%2C%0A%20%20Lag(%20%3ACumTimeYear%20)%20%2B%20Dif(%20%3AYear%20)%0A%20%2C%20%2F%2F%20else%20first%20row%0A%20%200%0A%20)%0A))%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
Lavik17
Level III

Calculate time difference and summing the values

I have a table with a time column with this format: m/d/y h:m:s

I would like to create a new column called CumTimeSec that will show the cumulative time difference up to that row.

For example,

Time

 

TimeCumTimeSec

5/11/2022 5:30:03 PM

0

5/11/2022 5:30:08 PM

5
5/11/2022 5:30:20 PM17
5/11/2022 5:30:23 PM 20

 

I figured I could use this code to calculate the difference between each row, but I'm not sure how to sum the values

dt << New Column( "CumTimeSec",
	Numeric,
	"Continuous",
	formula(  :Time - Lag( :Time) )
);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jasean
Staff

Re: Calculate time difference and summing the values

Hi Lavik17,

 

Lag is useful for this application, but you need to use it a couple of times.  Note that Dif() takes the difference between the current row and a "lag" row.  For example, above you calculate :Time - Lag(:Time).  That is the same as Dif(:Time).

 

Here is an example you can run with JMP sample data.  The table just lists a sequence of years, but it will work the same for a time column.

dt = Open("$SAMPLE_DATA/Time Series/SeriesQ.jmp");
dt << New Column("CumTimeYear", Formula(
	If( Row() > 1,
		Lag( :CumTimeYear ) + Dif( :Year )
	, // else first row
		0
	)
));

View solution in original post

3 REPLIES 3
Jasean
Staff

Re: Calculate time difference and summing the values

Hi Lavik17,

 

Lag is useful for this application, but you need to use it a couple of times.  Note that Dif() takes the difference between the current row and a "lag" row.  For example, above you calculate :Time - Lag(:Time).  That is the same as Dif(:Time).

 

Here is an example you can run with JMP sample data.  The table just lists a sequence of years, but it will work the same for a time column.

dt = Open("$SAMPLE_DATA/Time Series/SeriesQ.jmp");
dt << New Column("CumTimeYear", Formula(
	If( Row() > 1,
		Lag( :CumTimeYear ) + Dif( :Year )
	, // else first row
		0
	)
));
jthi
Super User

Re: Calculate time difference and summing the values

Haven't used Dif before but you could combine it Col Cumulative Sum

Col Cumulative Sum(Dif(:Time))
-Jarmo
Lavik17
Level III

Re: Calculate time difference and summing the values

Thanks @Jasean !! Worked like a charm!!

Recommended Articles