<?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: Formula to use previous value if not missing, otherwise use value from last occupied cell in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18105#M16507</link>
    <description>&lt;P&gt;Here is one version of the formula that works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1, lagval = . );&amp;nbsp;
x = Sum( :col 1, lagval );&amp;nbsp;
If( Is Missing( col 2 ) == 0,&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lagval = :col 2&amp;nbsp;
);
x;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Times New Roman; font-size: 12pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Aug 2019 17:34:25 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2019-08-13T17:34:25Z</dc:date>
    <item>
      <title>Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18104#M16506</link>
      <description>&lt;P&gt;I'm trying to write a formula in Col3 that adds the current value of Col1 with the lagged value of Col2 but I'm running into a pickle trying to figure out how to carry forward the last observation from Col2 when missing data is encountered and to use this value at the first instance of non-missing data.&amp;nbsp; That is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( !IsMissing( Col1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Col1 + Lag(Col2,1);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //create variable that contains current Col2 value;

//Else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Col1 + previously stored value from Col2;

);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would appreciate any suggestions on how best to accomplish this.&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE class="jiveBorder" style="border: 1px solid #c6c6c6; width: 100%;" border="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH style="text-align: left; background-color: #f2f2f2; color: #505050; padding: 6px;" valign="middle"&gt;Row#&lt;/TH&gt;
&lt;TH style="text-align: left; background-color: #f2f2f2; color: #505050; padding: 6px;" valign="middle"&gt;&lt;STRONG&gt;Col1&lt;/STRONG&gt;&lt;/TH&gt;
&lt;TH style="text-align: left; background-color: #f2f2f2; color: #505050; padding: 6px;" valign="middle"&gt;Col2&lt;/TH&gt;
&lt;TH style="text-align: left; background-color: #f2f2f2; color: #505050; padding: 6px;" valign="middle"&gt;Col3&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;1&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;2&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;1&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;4&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;2&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;7&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;7&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;5&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;.&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;.&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;6&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;.&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;.&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;7&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;.&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;.&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;8&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;2&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;8&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;9&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;2&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;9&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;10&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;1&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;11&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;11&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;.&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;.&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;13&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;.&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;.&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;14&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;2&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;12&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;13&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;15&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;2&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;13&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;14&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;16&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;1&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;14&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;14&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="padding: 6px;"&gt;17&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;2&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;15&lt;/TD&gt;
&lt;TD style="padding: 6px;"&gt;16&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 13 Aug 2019 17:32:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18104#M16506</guid>
      <dc:creator>terapin</dc:creator>
      <dc:date>2019-08-13T17:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18105#M16507</link>
      <description>&lt;P&gt;Here is one version of the formula that works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1, lagval = . );&amp;nbsp;
x = Sum( :col 1, lagval );&amp;nbsp;
If( Is Missing( col 2 ) == 0,&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lagval = :col 2&amp;nbsp;
);
x;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Times New Roman; font-size: 12pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 17:34:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18105#M16507</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-08-13T17:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18106#M16508</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think there's an error in your description that we'll have to clear up before we can give you a precise solution. Your conditional says if that if Col1 is NOT MISSING then add it to the lagged value of Col2, and if Col1 IS MISSING then add that to a previously stored value of Col2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can't add a missing Col1 to anything and get anything other than missing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Having said that, I would build this table out one column at a time. Specifically, I would create a "non-missing Col2" column which had no missing values using the formula:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11375_JMPScreenSnapz015.png" style="width: 1080px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2971i7BFEC9AB9D95E8D3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11375_JMPScreenSnapz015.png" alt="11375_JMPScreenSnapz015.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This formula sets "non-missing Col2" to Col2 when Col2 isn't missing and sets it to the Lag of "non-missing Col2" when Col2 is missing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11376_JMPScreenSnapz016.png" style="width: 1450px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2972iDA4532486507C2BE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11376_JMPScreenSnapz016.png" alt="11376_JMPScreenSnapz016.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You can then use a Lag(non-missing Col2, 1) in your final formula.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope that helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Jeff&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2016 02:27:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18106#M16508</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2016-10-19T02:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18107#M16509</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Jim and Jeff,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I made the issue more complicated than it needs to be in my description and table layout and can see how that may have led you to your suggestions.&lt;/P&gt;&lt;P&gt;While I understand your suggestion Jeff about creating a new column that holds the non-missing data I'm hoping to accomplish my work without creating new columns since I'll be using this formula for many different columns.&amp;nbsp; Let me try to be more clear about what I'm trying to accomplish by way of the table below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to create a running sum of Column 1 in Column 2.&amp;nbsp; Without creating any additional columns, I was hoping to create a variable that contains the current running sum value in Column 2 and adds that to the value of Column 1. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My issue is not knowing the best way to create and use a variable that contains the present value for Column 2 so that this value can be "carried" across rows of missing Column 1 data.&amp;nbsp; Column "Result I'm Looking For" shows what I would like the formula in Column 2 to produce.&amp;nbsp; Hopefully this description is a bit more clear about what I'm looking to accomplish.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11378_pastedImage_1.png" style="width: 996px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2973i60A200484E9D30A1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11378_pastedImage_1.png" alt="11378_pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2016 02:27:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18107#M16509</guid>
      <dc:creator>terapin</dc:creator>
      <dc:date>2016-10-19T02:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18108#M16510</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have we always been able to have a column Formula be self-referential?&amp;nbsp; I never realized I could do this.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Apr 2016 21:03:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18108#M16510</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2016-04-20T21:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18109#M16511</link>
      <description>&lt;P&gt;I think this formula will give you what you're after:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Is Missing( :Column 1 ),
	:Column 1,
	Summation( i = 1, Row(), :Column 1 )
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;
&lt;P&gt;-Jerry&lt;/P&gt;</description>
      <pubDate>Wed, 02 May 2018 14:49:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18109#M16511</guid>
      <dc:creator>jerry_cooper</dc:creator>
      <dc:date>2018-05-02T14:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18110#M16512</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks everyone for your comments and help.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think Jerry's suggestion works the best for me and didn't require the use of a local variable which is what I was wanting to use.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Apr 2016 18:00:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18110#M16512</guid>
      <dc:creator>terapin</dc:creator>
      <dc:date>2016-04-25T18:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18111#M16513</link>
      <description>&lt;P&gt;I run into this problem all of the time and use the solution give by Jerry. I analyze process measurements (temperature, pressure, flow, etc.) that are retrieved from a compressed-data-historian. Every few thousand points, there can be a missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example below calculates if reactor is running or not based on 3 point moving average of catalyst flow, F.Cat &amp;gt;= 11 (anonymized yes, you get the reference...). If F.Cat is missing, calc uses previous row's value of "Running?".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(
	Row() &amp;lt; 3, 0,
	Is Missing( :F.Cat ), Lag( :Name( "Running?" ), 1 ),
	(Lag( :F.Cat, 2 ) + Lag( :F.Cat, 1 ) + :F.Cat) / 3 &amp;gt;= 11, 1,
	0
)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 May 2018 14:24:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/18111#M16513</guid>
      <dc:creator>markschahl</dc:creator>
      <dc:date>2018-05-02T14:24:36Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/55963#M31435</link>
      <description>&lt;P&gt;I think this is exactly what I need as well, but I don't fully understand the script....is it possible to show what this would look like in the formula&amp;nbsp;editor...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks so much&lt;/P&gt;</description>
      <pubDate>Fri, 27 Apr 2018 14:27:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/55963#M31435</guid>
      <dc:creator>cjw0</dc:creator>
      <dc:date>2018-04-27T14:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56034#M31445</link>
      <description>&lt;P&gt;I believe this response was written prior to the release of JMP 13 which introduced the Col Cumulative Sum() function. If you are using v13 or higher, all you need do to create a cumulative sum column is right-click the column header for the column you wish to sum and select New Formula Column=&amp;gt;Row=&amp;gt;Cumulative Sum. This will create a new column with the appropriate formula. To see the formula in the editor, right-click the new column and select Formula.&lt;BR /&gt;&lt;BR /&gt;If you are using a prior version, copy and paste the following statement into the formula editor to see what it looks like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Summation(i=1, Row(), Your Column[i])&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 May 2018 14:00:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56034#M31445</guid>
      <dc:creator>jerry_cooper</dc:creator>
      <dc:date>2018-05-02T14:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56038#M31447</link>
      <description>&lt;P&gt;What I am tyring to do is ask the question....what is the date difference between two different biopsies (column labelled TCMR) for a given patient (pt number in first column) in my database. The biopsies occur at irregular intervales and the outcome of the biopsy is shown in the third column below.&lt;/P&gt;
&lt;P&gt;Although I know how to retrieve this information if I simply create a subset of only the rows which contain a biopsy result&amp;nbsp;and then ask for the date difference....what I would likel to do is figure out a way to determine the date difference between any to rows that have a biopsy result while ignoring the empty rows.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/1590"&gt;@jerry_cooper&lt;/a&gt;wrote:&lt;BR /&gt;
&lt;P&gt;I think this formula will give you what you're after:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(Is Missing(:Column 1), :Column 1, Summation(i = 1, Row(), :Column 1))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;
&lt;P&gt;-Jerry&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you help with this. &amp;nbsp;Ideally with a solution that I can see in the formula editor or can paste into it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 17:36:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56038#M31447</guid>
      <dc:creator>cjw0</dc:creator>
      <dc:date>2019-08-13T17:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56068#M31464</link>
      <description>&lt;P&gt;Unfortunately, I can't see the example table you provided, however, the enclosed file might give you an idea for an approach to take the difference between the current and previous non-missing dates.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The formula in the second column first establishes a matrix of rows for the non-missing cells in the Date column. This provides a way to reference the previous, non-missing row which is used as an index in the Date Difference function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm sure there are other ideas for doing this...&lt;/P&gt;</description>
      <pubDate>Sat, 28 Apr 2018 16:08:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56068#M31464</guid>
      <dc:creator>jerry_cooper</dc:creator>
      <dc:date>2018-04-28T16:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56208#M31551</link>
      <description>&lt;P&gt;Thanks Jerry. &amp;nbsp;This does look like exactly what I need.&lt;/P&gt;&lt;P&gt;Unfortunately I am a novice at this and I still need help figuring out how I can re-create this myself in my own database and&amp;nbsp;the formula editor. I have attached a very simplfied version of the column's of interest for a single patient in my data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my database there are many rows of data with lab values that we&amp;nbsp;are following, however, only some of the rows have a biopsy result. I want to create a formula that will use the dates in the "Dates" column to calculate the date difference between the biopsies whenever they occur.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately I don't understand which functions you have used to create your formula.... for example... although if have used the "Is missing" function many times I don't even see the option of "Loc Nonmissing" in the formula editor.&lt;/P&gt;&lt;P&gt;Also, what does "nm" mean.... I assume "something matrix" but where do I find that in the formula editor?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for the hassel but I am axious to learn this as it looks like exactly what I need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CW&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 21:07:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56208#M31551</guid>
      <dc:creator>cjw0</dc:creator>
      <dc:date>2018-05-01T21:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56237#M31567</link>
      <description>&lt;P&gt;You might find the &lt;A href="https://community.jmp.com/t5/JMP-Add-Ins/Data-Table-Tools-Add-in/ta-p/28582" target="_self"&gt;Data Table Tools&lt;/A&gt;&amp;nbsp;add-in helpful for such cases.&lt;/P&gt;</description>
      <pubDate>Wed, 02 May 2018 13:27:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56237#M31567</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2018-05-02T13:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56265#M31583</link>
      <description>&lt;P&gt;Sorry I didn't provide more of an explanation in my previous response. First, to make the formula work for your data table, change the "Date" column in the "If" statements to "Biopsy Result" and the "Hour" argument in the Date Difference function to whatever interval you need (i.e. "Day"):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1,
	nm = Loc Nonmissing( :Biopsy Result &amp;lt;&amp;lt; get values );
	.;
,
	If( Is Missing( :Biopsy Result ),
		.,
		Try( Date Difference( :Date[nm[Contains( nm, Row() ) - 1]], :Date, "Day" ) )
	)
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now for the explanation. The existing formulas don't automatically index backward or forward until they find non-missing data, so I resorted to scripting to create variables that contain the information needed. If you would like to learn more about scripting, the Help-&amp;gt;Books-&amp;gt;Scripting Guide and Help-&amp;gt;Scripting Index are great resources.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ":Biopsy Result&amp;lt;&amp;lt;Get Values" statement generates a list with all the values for Biopsy Result. Loc Nonmissing is a matrix function that finds all the positions in the list that are non-missing. The variable, "nm" stores this result, which now contains the row numbers for the non-missing Biopsy Result entries. Since this only needs to be created once, it is done for the first row only. Also, the result is set to missing for the first row.&lt;/P&gt;
&lt;P&gt;Next, if Biopsy Result is missing, the result is set to missing, otherwise, we need to reference the previous, non-missing Date for the Date Difference calculation. Contains(nm, Row()) finds the position of the current row in the "nm" matrix. Subtract 1 from this to find the position of the previous row in the "nm" matrix. This now is the index, i.e. row number, for the Date value in the row with the previous, non-missing Biopsy Result. The "Try" function ignores the error generated by the Date Difference function when there is no previous, non-missing row (i.e. the first instance of a Biopsy Result).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A couple of things to keep in mind, this assumes your data are sorted by date within ID # (as in your example). Also, if you have multiple ID #'s in your data table, you may want to add another condition so that you're not comparing two different ID's. In this case, your formula/script might look something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Row() == 1,
	nm = Loc Nonmissing( :Biopsy Result &amp;lt;&amp;lt; get values );
	.;
,
	If( Is Missing( :Biopsy Result ),
		.,
		If( :ID # == :ID #[nm[Contains( nm, Row() ) - 1]],
			Try( Date Difference( :Date[nm[Contains( nm, Row() ) - 1]], :Date, "Day" ) ),
			.
		)
	)
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I know this is a lot of info, but you did say you were "anxious to learn this"... hope this helps.&lt;/P&gt;</description>
      <pubDate>Wed, 02 May 2018 16:00:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56265#M31583</guid>
      <dc:creator>jerry_cooper</dc:creator>
      <dc:date>2018-05-02T16:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Formula to use previous value if not missing, otherwise use value from last occupied cell</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56518#M31756</link>
      <description>&lt;P&gt;Thank you Jerry for your great explaination and for anticipating my next question of incorporating the ID's!&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 18:20:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-to-use-previous-value-if-not-missing-otherwise-use-value/m-p/56518#M31756</guid>
      <dc:creator>cjw0</dc:creator>
      <dc:date>2018-05-07T18:20:25Z</dc:date>
    </item>
  </channel>
</rss>

