<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: trailing cumulative sum formula in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/341583#M59045</link>
    <description>&lt;P&gt;If you just want the sum, then don't divide the sum by anything&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1,
	holdMatrix = [];
	dateMatrix = [];
);
If( :Name( " Sea Surface Temperature (deg C)" ) &amp;gt; 31.3,
	holdMatrix = holdMatrix || 0.25;
	dateMatrix = dateMatrix || Informat( :date, "m/d/y" );
);
If( N Cols( dateMatrix ) != 0,
	While( dateMatrix[N Cols( dateMatrix )] &amp;gt; dateMatrix[1] + In Days( 120 ),
		holdMatrix[1] = [];
		dateMatrix[1] = [];
	);
	x = Sum( holdMatrix ) ;
,
	x = .
);
x;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 14 Dec 2020 14:35:26 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2020-12-14T14:35:26Z</dc:date>
    <item>
      <title>trailing cumulative sum formula</title>
      <link>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/340210#M58866</link>
      <description>&lt;P&gt;I have what is likely to be a very easy formula need. I have a temperature dataset and need to calculate a trailing cumulative sum over the past 120 days (known as "degree-heating weeks" since I will convert this sum to weeks by dividing by 7). I know how to get a trailing average, and I know how to get a cumulative sum, but is it possible to get a trailing, 120-day cumulative sum? In this case, when the temperature passes 31.3C, a "score" of 0.25 is given (see "DH-6 hrs" column for formula.). Basically, I want the cumulative sum of these 0.25 values over a 120-day window, but I only know how to partition by date/month/year, etc. (see "#DHWs" script for example), not by an actual window of time. I feel confident that this must be doable!&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:23:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/340210#M58866</guid>
      <dc:creator>abmayfield</dc:creator>
      <dc:date>2023-06-10T23:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: trailing cumulative sum formula</title>
      <link>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/340231#M58868</link>
      <description>&lt;P&gt;If I am interpreting correctly what you want, I believe the below formula will calculate a running 120 trailing cumulative sum&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1,
	holdMatrix = []
);
If( :Name( " Sea Surface Temperature (deg C)" ) &amp;gt; 31.3,
	holdMatrix = holdMatrix || Matrix( 0.25 ),
	holdMatrix = holdMatrix || Matrix( . )
);
If( N Cols( holdMatrix ) == 121,
	holdMatrix[1] = []
);
Sum( holdMatrix ) / 7;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Dec 2020 17:30:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/340231#M58868</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-12-08T17:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: trailing cumulative sum formula</title>
      <link>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/340232#M58869</link>
      <description>&lt;P&gt;Great! That did the trick. I just modified it to reflect the fact that there were eight measuring times per day (i.e., each row is not a unique day, so I multiplied the 121 x 8 = 968 in the evaluation). The data make sense because the value maxes out at the annual max that I had calculated before, before dropping off. Thanks so much. I wish there was a trailing cumulative sum in the formula editor that has similar inputs as the column moving average (which I use ALL the time): weight and N before. Maybe I'll add it to the Wish list.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2020 17:48:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/340232#M58869</guid>
      <dc:creator>abmayfield</dc:creator>
      <dc:date>2020-12-08T17:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: trailing cumulative sum formula</title>
      <link>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/341450#M59016</link>
      <description>&lt;P&gt;I have a question that arises from one annoying quirk in the dataset: I need to evaluate the cumulative sum in hours (not weeks, as I mentioned before) over the trailing 120-day period. However, the time intervals are inconsistent (see attached table). In MOST cases, there are 8 measurements/day, but sometimes it is less. Basically, any time the temperature is &amp;gt;31.3, I want to add the time difference to the column. This is easy enough using the "dif" function. However, where I struggle is how to add the "120 days" to the matrix-formula. So in the attached table, I want to do the cumulative sum of the "DHHs" over the trailing 120-day period. Rather than have the number of "rows" in the formula, I need it to track the date instead. Is that possible?&lt;/P&gt;</description>
      <pubDate>Sun, 13 Dec 2020 19:10:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/341450#M59016</guid>
      <dc:creator>abmayfield</dc:creator>
      <dc:date>2020-12-13T19:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: trailing cumulative sum formula</title>
      <link>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/341456#M59022</link>
      <description>&lt;P&gt;I am not exactly sure what divisor you are looking at using, but I used the number of hours over the range of the matrix of data.&amp;nbsp; Here is the formula I came up with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1,
	holdMatrix = [];
	dateMatrix = [];
);
If( :Name( " Sea Surface Temperature (deg C)" ) &amp;gt; 31.3,
	holdMatrix = holdMatrix || 0.25;
	dateMatrix = dateMatrix || Informat( :date, "m/d/y" );
);
If( N Cols( dateMatrix ) != 0,
	While( dateMatrix[N Cols( dateMatrix )] &amp;gt; dateMatrix[1] + In Days( 120 ),
		holdMatrix[1] = [];
		dateMatrix[1] = [];
	);
	x = Sum( holdMatrix ) / ((dateMatrix[N Cols( dateMatrix )] - dateMatrix[1]) / In Hours( 1 ));
,
	x = .
);
x;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Dec 2020 02:36:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/341456#M59022</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-12-14T02:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: trailing cumulative sum formula</title>
      <link>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/341582#M59044</link>
      <description>&lt;P&gt;Jim, thanks for looking at my question again, though it seems like the values resulting from your new formula are too low (despite the formula seemingly making sense). But maybe I should have stated my need differently, in which case there may be a simpler (or at least more straightforward solution): I am wanting to know the total number of HOURS in a trailing 120-day period in which the temperature was OVER 31.3C. This usually equates to 3-hr blocks since temperature is only measured every three hours (in most cases), so it's basically a series of sums of 3 (see "DHHs" column in attached table). Therefore, the values could be in the hundreds for the warmest months. So basically, I need a trailing 120-day sum of the DHH column, but it's tricky given the issue of differing numbers of measurements/day!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 14:03:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/341582#M59044</guid>
      <dc:creator>abmayfield</dc:creator>
      <dc:date>2020-12-14T14:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: trailing cumulative sum formula</title>
      <link>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/341583#M59045</link>
      <description>&lt;P&gt;If you just want the sum, then don't divide the sum by anything&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1,
	holdMatrix = [];
	dateMatrix = [];
);
If( :Name( " Sea Surface Temperature (deg C)" ) &amp;gt; 31.3,
	holdMatrix = holdMatrix || 0.25;
	dateMatrix = dateMatrix || Informat( :date, "m/d/y" );
);
If( N Cols( dateMatrix ) != 0,
	While( dateMatrix[N Cols( dateMatrix )] &amp;gt; dateMatrix[1] + In Days( 120 ),
		holdMatrix[1] = [];
		dateMatrix[1] = [];
	);
	x = Sum( holdMatrix ) ;
,
	x = .
);
x;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Dec 2020 14:35:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/341583#M59045</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-12-14T14:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: trailing cumulative sum formula</title>
      <link>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/341592#M59053</link>
      <description>&lt;P&gt;There is something strange going on still. If you look at this data table, you will find your formula (albeit modified slightly) in the "#DHWs (trailing 120 days)" column. There are some stretches of 4-6 months with no temperatures above 31.3C, yet the value never tapers off (such as October 2014-May 2015). If there are no temperatures above 31.3C for 120 days, the "#DHWs" should drop to 0. I feel like your formula SHOULD do this. I wonder if it's an issue arising from traversing from one year to another? Maybe I could jut recode "Day" from 1 to 20,000?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 16:42:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/341592#M59053</guid>
      <dc:creator>abmayfield</dc:creator>
      <dc:date>2020-12-14T16:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: trailing cumulative sum formula</title>
      <link>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/341930#M59093</link>
      <description>&lt;P&gt;I discovered an issue with the previous formula.&amp;nbsp; Missing values were causing an issue.&amp;nbsp; Also, the data needs to be in assending date order.&amp;nbsp; So please sort the table before applying the formula&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1,
	holdMatrix = [];
	dateMatrix = [];
);
If( Is Missing( :Name( "Date Time (UTC)" ) ) == 0,
	If(
		Is Missing( :Name( " Sea Surface Temperature (deg C)" ) ) == 1, holdMatrix = holdMatrix || 0,
		:Name( " Sea Surface Temperature (deg C)" ) &amp;gt; 31.3, holdMatrix = holdMatrix || :time difference 2,
		:Name( " Sea Surface Temperature (deg C)" ) &amp;lt;= 31.3, holdMatrix = holdMatrix || 0
	);
	dateMatrix = dateMatrix || Informat( :date, "m/d/y" );
	If( N Cols( dateMatrix ) &amp;amp; N Cols( holdMatrix ) != 0,
		While( dateMatrix[N Cols( dateMatrix )] &amp;gt; dateMatrix[1] + In Days( 120 ) &amp;amp; N Cols( holdMatrix ) &amp;gt; 0 &amp;amp; N Cols( dateMatrix ) &amp;gt; 0,
			dateMatrix[1] = [];
			holdMatrix[1] = [];
		);
		If( N Cols( dateMatrix ) &amp;amp; N Cols( holdMatrix ) != 0,
			x = Sum( holdMatrix ),
			x = .
		);
	,
		x = .
	);
,
	x = .
);
(x / 24) / 7;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Dec 2020 14:04:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/341930#M59093</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-12-15T14:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: trailing cumulative sum formula</title>
      <link>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/342272#M59118</link>
      <description>&lt;P&gt;Thanks for your perseverance! That did indeed appear to be an issue, and now the data make more sense. There is still an issue around October 2018 through June 2019: despite the temperature never rising above 31.3C, the value never drops to 0, even by June 2019 (well over 120 days). Can you tell what may be going on there?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2020 22:26:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/342272#M59118</guid>
      <dc:creator>abmayfield</dc:creator>
      <dc:date>2020-12-15T22:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: trailing cumulative sum formula</title>
      <link>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/342274#M59120</link>
      <description>&lt;P&gt;If you add the following to the formula&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == ????, 
     new table("row" || char(row()),new column("Values", set values(holdMatrix)),&lt;BR /&gt;     new column("dates", set values(dateMatrix), format("m/d/y")));
);
(x / 24) / 7;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and just replace the ???? with the row number of where you think the data is going funny, you will then see a data table with all of the values that were added into the value, and the dates the values were collected from.&amp;nbsp; That might give you a clue as to what is going on.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2020 22:54:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/342274#M59120</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-12-15T22:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: trailing cumulative sum formula</title>
      <link>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/342275#M59121</link>
      <description>&lt;P&gt;Below is a new formula that you can use for debugging.&amp;nbsp; It will create the data table for whatever row number you put into the If() statement at the end.&amp;nbsp; If you do not want to create a data table, then just change the row number that you are trying to find, to -1.&amp;nbsp; There will never be a -1 row, so a table will not be created.&amp;nbsp; Anyway, see if you can see what is going on and where an error is occurring.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure the table is sorted correctly and any rows you don't want to be processed are deleted from the table.&amp;nbsp; The script does not honor Excluded rows.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1,
	holdMatrix = [];
	dateMatrix = [];
	rowMatrix = [];
);
If( Is Missing( :Name( "Date Time (UTC)" ) ) == 0,
	If(
		Is Missing( :Name( " Sea Surface Temperature (deg C)" ) ) == 1, holdMatrix = holdMatrix || 0,
		:Name( " Sea Surface Temperature (deg C)" ) &amp;gt; 31.3, holdMatrix = holdMatrix || :time difference 2,
		:Name( " Sea Surface Temperature (deg C)" ) &amp;lt;= 31.3, holdMatrix = holdMatrix || 0
	);
	dateMatrix = dateMatrix || Informat( :date, "m/d/y" );
	rowMatrix = rowMatrix || Row();
	If( N Cols( dateMatrix ) &amp;amp; N Cols( holdMatrix ) != 0,
		While(
			dateMatrix[N Cols( dateMatrix )] &amp;gt; dateMatrix[1] + In Days( 120 ) &amp;amp; N Cols( holdMatrix ) &amp;gt; 0 &amp;amp;
			N Cols( dateMatrix ) &amp;gt; 0,
			dateMatrix[1] = [];
			holdMatrix[1] = [];
			rowMatrix[1] = [];
		);
		If( N Cols( dateMatrix ) &amp;amp; N Cols( holdMatrix ) != 0,
			x = Sum( holdMatrix ),
			x = .
		);
	,
		x = .
	);
,
	x = .
);
If( Row() == 22159,
	New Table( "row" || Char( Row() ),
		New Column( "RowNum", set values( rowMatrix ) ),
		New Column( "Values", set values( holdMatrix ) ),
		New Column( "dates", set values( dateMatrix ), Format( "m/d/y" ) )
	)
);
(x / 24) / 7;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Dec 2020 22:53:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/trailing-cumulative-sum-formula/m-p/342275#M59121</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-12-15T22:53:22Z</dc:date>
    </item>
  </channel>
</rss>

