<?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: Number of rows until event in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Number-of-rows-until-event/m-p/420085#M66890</link>
    <description>&lt;P&gt;Maybe we can use is the fact that the solution, if the row order is reversed, is self populated in JMP?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="event reversed.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/35991iD2492C320390E2C4/image-size/large?v=v2&amp;amp;px=999" role="button" title="event reversed.png" alt="event reversed.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, this will reverse the order of the events.&lt;/P&gt;&lt;P&gt;Event reversed:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;:Event[(N Rows() - Row()) + 1]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now the values self-populate as the calculation works from top to bottom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;n rows after the reversed event:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( :Event inverted == 1, 0,
Lag( :n rows after inverted event, 1 ) + 1
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, we reversed that column.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;:n rows after reversed event[(N Rows() - Row()) + 1]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any ideas on how to do this in one formula which is easy to interpret?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Sep 2021 12:11:18 GMT</pubDate>
    <dc:creator>FN</dc:creator>
    <dc:date>2021-09-22T12:11:18Z</dc:date>
    <item>
      <title>Number of rows until event</title>
      <link>https://community.jmp.com/t5/Discussions/Number-of-rows-until-event/m-p/419812#M66877</link>
      <description>&lt;P&gt;Without using JSL, is there a way to calculate a column that tells you how many rows are left until an event happens?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following formula works but needs the user to click n times in "Apply"&lt;/P&gt;&lt;P&gt;Can we put this formula inside a for loop that 'applies it' n times?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="event.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/35984i4F10D893C6E3E820/image-size/large?v=v2&amp;amp;px=999" role="button" title="event.png" alt="event.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:37:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Number-of-rows-until-event/m-p/419812#M66877</guid>
      <dc:creator>FN</dc:creator>
      <dc:date>2023-06-10T23:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Number of rows until event</title>
      <link>https://community.jmp.com/t5/Discussions/Number-of-rows-until-event/m-p/419829#M66878</link>
      <description>&lt;P&gt;You could use more complicated formula. Something like this could work (might not handle all special cases correctly):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(Row() == 1,
	m_events = Loc(:Event &amp;lt;&amp;lt; get as matrix, 1);
);
smallerRows = Loc(Row() &amp;lt;= m_events);
If(N Items(smallerRows) == 0,
	0,
	rowNextEvent = m_events[smallerRows[1]];
	If(rowNextEvent,
		rowNextEvent - Row();
	);	
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 20:37:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Number-of-rows-until-event/m-p/419829#M66878</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-09-21T20:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: Number of rows until event</title>
      <link>https://community.jmp.com/t5/Discussions/Number-of-rows-until-event/m-p/420085#M66890</link>
      <description>&lt;P&gt;Maybe we can use is the fact that the solution, if the row order is reversed, is self populated in JMP?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="event reversed.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/35991iD2492C320390E2C4/image-size/large?v=v2&amp;amp;px=999" role="button" title="event reversed.png" alt="event reversed.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, this will reverse the order of the events.&lt;/P&gt;&lt;P&gt;Event reversed:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;:Event[(N Rows() - Row()) + 1]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now the values self-populate as the calculation works from top to bottom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;n rows after the reversed event:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( :Event inverted == 1, 0,
Lag( :n rows after inverted event, 1 ) + 1
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, we reversed that column.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;:n rows after reversed event[(N Rows() - Row()) + 1]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any ideas on how to do this in one formula which is easy to interpret?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 12:11:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Number-of-rows-until-event/m-p/420085#M66890</guid>
      <dc:creator>FN</dc:creator>
      <dc:date>2021-09-22T12:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: Number of rows until event</title>
      <link>https://community.jmp.com/t5/Discussions/Number-of-rows-until-event/m-p/420171#M66898</link>
      <description>&lt;P&gt;At this point I will have to ask: what are we looking for here? Single formula which is also self-explanatory?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The formula I did provide is a single formula (will require small change to handle cases if there are no events after some specific point) but hardly self-explanatory, but can made closer to one by using supporting variables with good names.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 14:35:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Number-of-rows-until-event/m-p/420171#M66898</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-09-22T14:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Number of rows until event</title>
      <link>https://community.jmp.com/t5/Discussions/Number-of-rows-until-event/m-p/420203#M66901</link>
      <description>&lt;P&gt;I am after a formula that is very simple to explain to new JMP users.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Adding my original formula inside a loop, so you don't need to click in apply, will be the easiest to explain.&lt;/LI&gt;&lt;LI&gt;Reversing the order is intuitive but takes extra steps (see above)&lt;/LI&gt;&lt;LI&gt;A solution that creates temporary variables looks like a script made into a formula (programmer mindset, not ideal for new users).&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So maybe it is as simple as asking, how can I loop a formula so it is applied N times?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 15:09:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Number-of-rows-until-event/m-p/420203#M66901</guid>
      <dc:creator>FN</dc:creator>
      <dc:date>2021-09-22T15:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: Number of rows until event</title>
      <link>https://community.jmp.com/t5/Discussions/Number-of-rows-until-event/m-p/420267#M66908</link>
      <description>&lt;P&gt;Nothing simple which wouldn't require JSL doesn't come to my mind which would allow you to use the original formula without pressing apply or using rerun formulas multiple times. Even building formulas is a bit difficult due to the no variables in this case (even for loop has variable for index).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example this cannot easily handle last rows if there is no events after them (also the formula isn't simple to explain):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(:Event == 1,
	0,
	For(i = 1, i &amp;lt;= N Rows() - Row(), i++,
		If(Lag(:Event, -1*i) == 1,
			Break();
		);
	);
	i;
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Sep 2021 16:47:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Number-of-rows-until-event/m-p/420267#M66908</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-09-22T16:47:39Z</dc:date>
    </item>
  </channel>
</rss>

