cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMPĀ® Marketplace featured Capability Explorer add-in
%3CLINGO-SUB%20id%3D%22lingo-sub-241410%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E8%A8%88%E7%AE%97%E6%BB%AF%E5%BE%8C%20x%20%E8%A1%8C%E7%9A%84%E7%B8%BD%E5%92%8C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-241410%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E6%88%91%E6%AD%A3%E5%9C%A8%E5%98%97%E8%A9%A6%E5%89%B5%E5%BB%BA%E4%B8%80%E5%80%8B%E5%88%97%E4%BE%86%E8%A8%88%E7%AE%97%E6%BB%AF%E5%BE%8C%2024%20%E8%A1%8C%E7%9A%84%E7%B8%BD%E5%92%8C%E3%80%82%20%E5%9C%A8%E6%9C%AC%E4%BE%8B%E4%B8%AD%EF%BC%8C%E6%88%91%E6%9C%89%E4%B8%80%E5%80%8B%E2%80%9CPrecip%E2%80%9D%E5%88%97%EF%BC%8C%E5%85%B6%E4%B8%AD%E5%8C%85%E5%90%AB%E6%AF%8F%E5%B0%8F%E6%99%82%E9%99%8D%E6%B0%B4%E7%B8%BD%E9%87%8F%E3%80%82%20%E7%AC%AC%E4%BA%8C%E5%88%97%E2%80%9C%E9%99%8D%E6%B0%B4%E7%AB%99%E2%80%9D%E8%A1%A8%E7%A4%BA%E8%A8%98%E9%8C%84%E6%AF%8F%E5%80%8B%E5%80%BC%E7%9A%84%E4%BD%8D%E7%BD%AE%E3%80%82%20%E6%88%91%E5%B7%B2%E6%A0%B9%E6%93%9A%E2%80%9C%E6%97%A5%E6%9C%9F%E6%99%82%E9%96%93%E2%80%9D%E5%92%8C%E2%80%9C%E9%99%8D%E6%B0%B4%E7%AB%99%E2%80%9D%E5%B0%8D%E5%88%97%E9%80%B2%E8%A1%8C%E6%8E%92%E5%BA%8F%E3%80%82%20%E6%88%91%E6%AD%A3%E5%9C%A8%E5%B0%8B%E6%89%BE%E4%B8%80%E7%A8%AE%E6%9C%89%E6%95%88%E7%9A%84%E6%96%B9%E6%B3%95%E4%BE%86%E5%B0%8D%20Precip%20%E5%88%97%E4%B8%AD%E7%9A%84%E5%89%8D%2024%20%E5%80%8B%E5%80%BC%E9%80%B2%E8%A1%8C%E6%B1%82%E5%92%8C%EF%BC%8C%E5%BE%9E%E8%80%8C%E5%89%B5%E5%BB%BA%E4%B8%80%E5%80%8B%E6%96%B0%E5%88%97%E4%BE%86%E5%91%8A%E8%A8%B4%E6%88%91%E9%81%8E%E5%8E%BB%2024%20%E5%B0%8F%E6%99%82%E5%85%A7%E4%B8%8B%E4%BA%86%E5%A4%9A%E5%B0%91%E9%9B%A8%E3%80%82%20%E6%AD%A4%2024%20%E5%B0%8F%E6%99%82%E7%B8%BD%E8%A8%88%E6%98%AF%E7%89%B9%E5%AE%9A%E6%96%BC%E7%AB%99%E9%BB%9E%E7%9A%84%EF%BC%8C%E5%9B%A0%E6%AD%A4%E5%A6%82%E6%9E%9C%E6%BB%AF%E5%BE%8C%2024%20%E9%99%8D%E6%B0%B4%E9%87%8F%E4%B8%8D%E5%8C%B9%E9%85%8D%EF%BC%8C%E5%89%87%E7%84%A1%E6%B3%95%E8%A8%88%E7%AE%97%E6%BB%AF%E5%BE%8C%2024%20%E5%80%BC%E3%80%82%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-241590%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E8%A8%88%E7%AE%97%E6%BB%AF%E5%BE%8C%20x%20%E8%A1%8C%E7%9A%84%E7%B8%BD%E5%92%8C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-241590%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E6%88%91%E6%9C%80%E7%B5%82%E8%87%AA%E5%B7%B1%E8%A7%A3%E6%B1%BA%E4%BA%86%E9%80%99%E5%80%8B%E5%95%8F%E9%A1%8C%EF%BC%8C%E9%80%99%E6%98%AF%E4%B8%80%E5%80%8B%E7%B0%A1%E5%96%AE%E7%9A%84%E6%B1%82%E5%92%8C%E5%87%BD%E6%95%B8%E3%80%82%20%E6%88%91%E6%83%B3%E6%88%91%E6%9C%83%E7%99%BC%E5%B8%83%E5%AE%83%E4%BB%A5%E9%98%B2%E5%85%B6%E4%BB%96%E4%BA%BA%E9%9C%80%E8%A6%81%E5%81%9A%E9%80%99%E6%A8%A3%E7%9A%84%E4%BA%8B%E6%83%85%E3%80%82%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EIf(%20%3APrecipitation%20Station%20%3D%3D%20Lag(%20%3APrecipitation%20Station%2C%201%20)%2C%0A%20Summation(%20i%20%3D%201%2C%2024%2C%20Lag(%20%3APrecipitation%2C%20i%20)%20)%2C%0A%20%3APrecipitation%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-241437%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E8%A8%88%E7%AE%97%E6%BB%AF%E5%BE%8C%20x%20%E8%A1%8C%E7%9A%84%E7%B8%BD%E5%92%8C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-241437%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E6%88%91%E5%AF%A6%E9%9A%9B%E4%B8%8A%E4%B8%A6%E4%B8%8D%E6%98%AF%E5%9C%A8%E5%98%97%E8%A9%A6%E8%A8%88%E7%AE%97%E7%B5%A6%E5%AE%9A%E7%AB%99%E9%BB%9E%2F%E6%97%A5%E6%9C%9F%E7%9A%84%E7%B8%BD%E9%99%8D%E6%B0%B4%E9%87%8F%EF%BC%8C%E8%80%8C%E6%98%AF%E8%A8%88%E7%AE%97%E7%AB%99%E9%BB%9E%2F%E5%89%8D%2024%20%E5%B0%8F%E6%99%82%E5%85%A7%E7%9A%84%E7%B8%BD%E9%99%8D%E6%B0%B4%E9%87%8F%E3%80%82%E5%9B%A0%E6%AD%A4%EF%BC%8C%E4%BE%8B%E5%A6%82%EF%BC%8C%E5%A6%82%E6%9E%9C%E7%B5%A6%E5%AE%9A%E7%9A%84%E6%97%A5%E6%9C%9F%E6%99%82%E9%96%93%E6%98%AF%201%2F3%2F2020%2009%3A00%3A00%20AM%EF%BC%8C%E6%88%91%E6%83%B3%E7%8D%B2%E5%8F%96%20precip%20%E5%88%97%E4%B8%AD%E7%9A%84%E5%89%8D%2024%20%E5%80%8B%E5%80%BC%E4%B8%A6%E5%B0%8D%E5%AE%83%E5%80%91%E6%B1%82%E5%92%8C%E3%80%82%20%E5%9B%A0%E6%AD%A4%EF%BC%8C%E5%BE%9E%201%2F3%2F2020%2008%3A00%3A00AM%20%E9%96%8B%E5%A7%8B%EF%BC%8C%E4%B8%80%E7%9B%B4%E5%9B%9E%E5%88%B0%201%2F2%2F2020%2009%3A00%3A00%20AM%E3%80%82%E6%9C%AC%E8%B3%AA%E4%B8%8A%E6%98%AF%E4%B8%80%E5%80%8B%E7%A7%BB%E5%8B%95%E7%9A%84%2024%20%E5%B0%8F%E6%99%82%E6%99%82%E9%96%93%E7%AA%97%E5%8F%A3%E3%80%82%20%E5%9B%A0%E6%AD%A4%EF%BC%8C%E8%A9%B2%E5%88%97%E5%B0%87%E7%82%BA%E6%88%91%E6%8F%90%E4%BE%9B%E6%95%B8%E6%93%9A%E8%A1%A8%E4%B8%AD%E6%AF%8F%E4%B8%80%E8%A1%8C%E9%81%8E%E5%8E%BB%2024%20%E5%B0%8F%E6%99%82%E5%85%A7%E7%9A%84%E9%99%8D%E9%9B%A8%E9%87%8F%E3%80%82%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-241436%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E8%A8%88%E7%AE%97%E6%BB%AF%E5%BE%8C%20x%20%E8%A1%8C%E7%9A%84%E7%B8%BD%E5%92%8C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-241436%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Precip.png%22%20style%3D%22width%3A%20734px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Precip.png%22%20style%3D%22width%3A%20734px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Precip.png%22%20style%3D%22width%3A%20734px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F21000iD4CFF40B4B8FBF7D%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Precip.png%22%20alt%3D%22Precip.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-241434%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E8%A8%88%E7%AE%97%E6%BB%AF%E5%BE%8C%20x%20%E8%A1%8C%E7%9A%84%E7%B8%BD%E5%92%8C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-241434%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E5%A6%82%E6%9E%9C%E6%82%A8%E5%98%97%E8%A9%A6%E8%A8%88%E7%AE%97%E7%B5%A6%E5%AE%9A%E6%97%A5%E6%9C%9F%2F%E7%AB%99%E9%BB%9E%E7%9A%84%E9%99%8D%E6%B0%B4%E9%87%8F%E7%B8%BD%E5%92%8C%EF%BC%8C%E8%AB%8B%E5%89%B5%E5%BB%BA%E4%B8%80%E5%80%8B%E6%96%B0%E5%88%97%EF%BC%8C%E8%A9%B2%E5%88%97%E5%8F%AA%E6%98%AF%E6%97%A5%E6%9C%9F%E6%99%82%E9%96%93%E7%9A%84%E6%97%A5%E6%9C%9F%E9%83%A8%E5%88%86%E3%80%82%E7%84%B6%E5%BE%8C%E6%8C%89%E6%97%A5%E6%9C%9F%E5%92%8C%E7%AB%99%E9%BB%9E%E8%A3%BD%E4%BD%9C%E8%A1%A8%E6%A0%BC%EF%BC%8C%E4%B8%A6%E5%B0%87%20Precip%20%E6%94%BE%E5%9C%A8%E4%B8%AD%E9%96%93%E3%80%82%3C%2FP%3E%0A%3CP%3E%E8%A9%B2%E7%A8%8B%E5%BA%8F%E5%89%B5%E5%BB%BA%E4%B8%80%E5%80%8B%E7%A4%BA%E4%BE%8B%E6%95%B8%E6%93%9A%E9%9B%86%EF%BC%8C%E5%85%B6%E4%B8%AD%E5%8C%85%E5%90%AB%E6%97%A5%E6%9C%9F%E5%85%AC%E5%BC%8F%E5%88%97%E5%92%8C%E8%A3%BD%E8%A1%A8%E7%A8%8B%E5%BA%8F%E4%BB%A5%E6%8C%89%E6%97%A5%E6%9C%9F%2F%E7%AB%99%E9%BB%9E%E8%A8%88%E7%AE%97%E9%99%8D%E6%B0%B4%E9%87%8F%E3%80%82%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENew%20Table(%20%22Example%22%2C%20Add%20Rows(%2020%20)%2C%0A%20New%20Script(%20%22Tabulate%22%2C%20%0A%20%20Tabulate(%0A%20%20%20Show%20Control%20Panel(%200%20)%2C%0A%20%20%20Add%20Table(%0A%20%20%20%20Column%20Table(%20Analysis%20Columns(%20%3APrecip%20)%20)%2C%0A%20%20%20%20Row%20Table(%20Grouping%20Columns(%20%3APrecip%20Date%2C%20%3AStation%20)%20)%0A%20%20%20)%0A%20%20)%0A%20)%2C%0A%20New%20Column(%20%22Precip%20Datetime%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%20%22ddMonyyyy%20h%3Am%3As%22%2C%2022%2C%200%20)%2C%0A%20%20Input%20Format(%20%22ddMonyyyy%20h%3Am%3As%22%2C%200%20)%2C%0A%20%20Set%20Values(%0A%20%20%20%5B3660710400%2C%203660714000%2C%203660717600%2C%203660721200%2C%203660724800%2C%203660710400%2C%0A%20%20%203660714000%2C%203660717600%2C%203660721200%2C%203660724800%2C%203660796800%2C%203660800400%2C%0A%20%20%203660804000%2C%203660807600%2C%203660811200%2C%203660796800%2C%203660800400%2C%203660804000%2C%0A%20%20%203660807600%2C%203660811200%5D%0A%20%20)%2C%0A%20%20Set%20Display%20Width(%20186%20)%0A%20)%2C%0A%20New%20Column(%20%22Station%22%2C%20Character%2C%20%22Nominal%22%2C%0A%20%20Set%20Values(%0A%20%20%20%7B%22A%22%2C%20%22A%22%2C%20%22A%22%2C%20%22A%22%2C%20%22A%22%2C%20%22B%22%2C%20%22B%22%2C%20%22B%22%2C%20%22B%22%2C%20%22B%22%2C%20%22A%22%2C%20%22A%22%2C%20%22A%22%2C%20%22A%22%2C%0A%20%20%20%22A%22%2C%20%22B%22%2C%20%22B%22%2C%20%22B%22%2C%20%22B%22%2C%20%22B%22%7D%0A%20%20)%0A%20)%2C%0A%20New%20Column(%20%22Precip%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%20%22Best%22%2C%2012%20)%2C%0A%20%20Set%20Values(%20%5B1%2C%202%2C%203%2C%204%2C%205%2C%203%2C%204%2C%205%2C%201%2C%201%2C%204%2C%205%2C%206%2C%207%2C%205%2C%204%2C%205%2C%206%2C%207%2C%208%5D%20)%0A%20)%2C%0A%20New%20Column(%20%22Precip%20Date%22%2C%20Character%2C%20%22Nominal%22%2C%0A%20%20Formula(%20Short%20Date(%20%3APrecip%20Datetime%20)%20)%0A%20)%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
RVhydrA
Level III

calculating sum of lag x rows

I am trying to create a column that calculates the sum of the lag 24 rows. In this instance I have a column "Precip" that contains hourly precipitation totals. There is a second column  "precipitation station" denoting from which location each value was recorded. I have sorted the columns based on "DateTime" and the "Precipitation Station". I am looking for an efficient way to sum the previous 24 values in the Precip column thus creating a new column that tells me how much it rained in the previous 24 hours. This 24 hour total is station specific so it cannot calculate the lag 24 values if the lag 24 precipitations do not match. 

1 ACCEPTED SOLUTION

Accepted Solutions
RVhydrA
Level III

Re: calculating sum of lag x rows

I ended up figuring this out on my own, it is a simple summation function. Figured i'd post it in case anyone else needs to do something like this. 

 

 

If( :Precipitation Station == Lag( :Precipitation Station, 1 ),
	Summation( i = 1, 24, Lag( :Precipitation, i ) ),
	:Precipitation
);

 

 

View solution in original post

4 REPLIES 4
pmroz
Super User

Re: calculating sum of lag x rows

If you are trying to calculate the sum of precipitation for a given day/station, create a new column which is just the date part of the datetime.  Then do a tabulation by date and station, and put Precip in the middle.

This program creates an example dataset with a formula column for date and a Tabulate program to calculate the precipitation by date/station.

New Table( "Example", Add Rows( 20 ),
	New Script( "Tabulate", 
		Tabulate(
			Show Control Panel( 0 ),
			Add Table(
				Column Table( Analysis Columns( :Precip ) ),
				Row Table( Grouping Columns( :Precip Date, :Station ) )
			)
		)
	),
	New Column( "Precip Datetime", Numeric, "Continuous", Format( "ddMonyyyy h:m:s", 22, 0 ),
		Input Format( "ddMonyyyy h:m:s", 0 ),
		Set Values(
			[3660710400, 3660714000, 3660717600, 3660721200, 3660724800, 3660710400,
			3660714000, 3660717600, 3660721200, 3660724800, 3660796800, 3660800400,
			3660804000, 3660807600, 3660811200, 3660796800, 3660800400, 3660804000,
			3660807600, 3660811200]
		),
		Set Display Width( 186 )
	),
	New Column( "Station", Character, "Nominal",
		Set Values(
			{"A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "A", "A", "A", "A",
			"A", "B", "B", "B", "B", "B"}
		)
	),
	New Column( "Precip", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 2, 3, 4, 5, 3, 4, 5, 1, 1, 4, 5, 6, 7, 5, 4, 5, 6, 7, 8] )
	),
	New Column( "Precip Date", Character, "Nominal",
		Formula( Short Date( :Precip Datetime ) )
	)
);
pmroz
Super User

Re: calculating sum of lag x rows

Precip.png

RVhydrA
Level III

Re: calculating sum of lag x rows

I'm not actually trying to compute the total precip for a given station/date, but rather station/previous 24 hour period. so for example if the DateTime for a given for is 1/3/2020 09:00:00 AM I would want to take the previous 24 values in the precip column and sum those. So starting with 1/3/2020 08:00:00AM and going all the way back to 1/2/2020 09:00:00 AM. Essentially a moving 24 hour window of time. This column would thus give me the previous rain over the prior 24 hours for each row in my data table.

RVhydrA
Level III

Re: calculating sum of lag x rows

I ended up figuring this out on my own, it is a simple summation function. Figured i'd post it in case anyone else needs to do something like this. 

 

 

If( :Precipitation Station == Lag( :Precipitation Station, 1 ),
	Summation( i = 1, 24, Lag( :Precipitation, i ) ),
	:Precipitation
);