<?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: Streamstats change state count in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Streamstats-change-state-count/m-p/467216#M131483</link>
    <description>&lt;P&gt;Looks good! thank you.&lt;BR /&gt;
If I observed any issue I will revert back. thanks again.&lt;/P&gt;</description>
    <pubDate>Fri, 29 May 2020 17:39:23 GMT</pubDate>
    <dc:creator>ips_mandar</dc:creator>
    <dc:date>2020-05-29T17:39:23Z</dc:date>
    <item>
      <title>Streamstats change state count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Streamstats-change-state-count/m-p/467214#M131481</link>
      <description>&lt;P&gt;Hi below is my sample data-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;Date State
29-05-20 01:00:00  On
29-05-20 01:10:00  Off
29-05-20 01:20:00  On
29-05-20 01:30:00  On
29-05-20 01:50:00  Off
29-05-20 01:55:00  On
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here I want to calculate "Number of Times State Went from On to Off" and "Number of Times State Went from Off to On" using streamstats command.&lt;BR /&gt;In above case results will be-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;"Number of Times State Went from On to Off" |"Number of Times State Went from Off to On"
    2                                                      2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jun 2020 19:36:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Streamstats-change-state-count/m-p/467214#M131481</guid>
      <dc:creator>ips_mandar</dc:creator>
      <dc:date>2020-06-08T19:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: Streamstats change state count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Streamstats-change-state-count/m-p/467215#M131482</link>
      <description>&lt;P&gt;@ips_mandar &lt;BR /&gt;
Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH | streamstats window=2 list(State) as S | eval Status=case(mvindex(S,0)="On" AND mvindex(S,1)="Off","Number of Times State Went from On to Off",mvindex(S,0)="Off" AND mvindex(S,1)="On","Number of Times State Went from Off to On") | stats count by Status | transpose header_field=Status | fields - column
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;My Sample Search:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval _raw="Date,State
29-05-20 01:00:00,On
29-05-20 01:10:00,Off
29-05-20 01:20:00,On
29-05-20 01:30:00,On
29-05-20 01:50:00,Off
29-05-20 01:55:00,On" | multikv forceheader=1 | table Date State | streamstats window=2 list(State) as S | eval Status=case(mvindex(S,0)="On" AND mvindex(S,1)="Off","Number of Times State Went from On to Off",mvindex(S,0)="Off" AND mvindex(S,1)="On","Number of Times State Went from Off to On") | stats count by Status | transpose header_field=Status | fields - column
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 15:31:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Streamstats-change-state-count/m-p/467215#M131482</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2020-05-29T15:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Streamstats change state count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Streamstats-change-state-count/m-p/467216#M131483</link>
      <description>&lt;P&gt;Looks good! thank you.&lt;BR /&gt;
If I observed any issue I will revert back. thanks again.&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 17:39:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Streamstats-change-state-count/m-p/467216#M131483</guid>
      <dc:creator>ips_mandar</dc:creator>
      <dc:date>2020-05-29T17:39:23Z</dc:date>
    </item>
  </channel>
</rss>

