<?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: Calculate moving average based on 2 categorical columns and on combined data in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Calculate-moving-average-based-on-2-categorical-columns-and-on/m-p/386109#M63623</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;I've adjusted the code to also calculate the moving average for Trial == After, so that seems to be working. But I noticed that the code wasn't calculating the moving average for TrialWeek == 1 unless I had the table sorted.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;x = .;
curWeek = :TrialWeek;
If(
	:Trial == "Before" &amp;amp; :TrialWeek != :TrialWeek[Row() + 1], x = Col Mean( If( :Trial == "Before" &amp;amp; :TrialWeek &amp;lt;= curWeek, :Dozens, . ) ),
	:Trial == "After" &amp;amp; :TrialWeek != :TrialWeek[Row() + 1], x = Col Mean( If( :Trial == "After" &amp;amp; :TrialWeek &amp;lt;= curWeek, :Dozens, . ) )
);
x;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 May 2021 04:25:31 GMT</pubDate>
    <dc:creator>CJenvey</dc:creator>
    <dc:date>2021-05-18T04:25:31Z</dc:date>
    <item>
      <title>Calculate moving average based on 2 categorical columns and on combined data</title>
      <link>https://community.jmp.com/t5/Discussions/Calculate-moving-average-based-on-2-categorical-columns-and-on/m-p/385687#M63580</link>
      <description>&lt;P&gt;I have a dataset with mean Dozens of eggs per OrderId and OrderDate for Trial (Before, After) and TrialWeek (1, 2, 3, 4, 5). I would like to use the Moving Average function to calculate the mean Dozens at the end of every week, using the data from the previous weeks, and then input this number into a new column. So there should be repeated mean dozens for every row that have the same Trial and TrialWeek.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;Trial == Before &amp;amp; TrialWeek == 1 = Mean Dozens for TrialWeek 1&lt;/P&gt;&lt;P&gt;Trial == Before &amp;amp; TrialWeek == 1 &amp;amp; 2 = Mean Dozens TrialWeek 2&lt;/P&gt;&lt;P&gt;Trial == Before &amp;amp; TrialWeek == 1 &amp;amp; 2 &amp;amp; 3 = Mean Dozens TrialWeek 3, and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Moving Average wants me to input the number of rows that the average is calculated on, however the number of rows per TrialWeek is not the same, so I can't use a fixed number of rows to calculate this. I know that I will need to write a formula to do this, but I'm stuck as to how to compose the formula. I am using JMP Pro 16. Any help would be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 19:46:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculate-moving-average-based-on-2-categorical-columns-and-on/m-p/385687#M63580</guid>
      <dc:creator>CJenvey</dc:creator>
      <dc:date>2023-06-09T19:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate moving average based on 2 categorical columns and on combined data</title>
      <link>https://community.jmp.com/t5/Discussions/Calculate-moving-average-based-on-2-categorical-columns-and-on/m-p/385709#M63581</link>
      <description>&lt;P&gt;Is this what you are looking for?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="trial.PNG" style="width: 819px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32880iFC47295AC62A9AAC/image-size/large?v=v2&amp;amp;px=999" role="button" title="trial.PNG" alt="trial.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;x = .;
curWeek = :TrialWeek;
If( :Trial == "Before" &amp;amp; :TrialWeek != :TrialWeek[Row() + 1],
	x = Col Mean( If( :Trial == "Before" &amp;amp; :TrialWeek &amp;lt;= curWeek, :Dozens, . ) )
);
x;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 May 2021 05:55:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculate-moving-average-based-on-2-categorical-columns-and-on/m-p/385709#M63581</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-05-17T05:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate moving average based on 2 categorical columns and on combined data</title>
      <link>https://community.jmp.com/t5/Discussions/Calculate-moving-average-based-on-2-categorical-columns-and-on/m-p/386109#M63623</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;I've adjusted the code to also calculate the moving average for Trial == After, so that seems to be working. But I noticed that the code wasn't calculating the moving average for TrialWeek == 1 unless I had the table sorted.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;x = .;
curWeek = :TrialWeek;
If(
	:Trial == "Before" &amp;amp; :TrialWeek != :TrialWeek[Row() + 1], x = Col Mean( If( :Trial == "Before" &amp;amp; :TrialWeek &amp;lt;= curWeek, :Dozens, . ) ),
	:Trial == "After" &amp;amp; :TrialWeek != :TrialWeek[Row() + 1], x = Col Mean( If( :Trial == "After" &amp;amp; :TrialWeek &amp;lt;= curWeek, :Dozens, . ) )
);
x;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 04:25:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculate-moving-average-based-on-2-categorical-columns-and-on/m-p/386109#M63623</guid>
      <dc:creator>CJenvey</dc:creator>
      <dc:date>2021-05-18T04:25:31Z</dc:date>
    </item>
  </channel>
</rss>

