<?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: subtract meterRead from Yesterday’s meterRead in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492293#M137329</link>
    <description>&lt;P&gt;I do have multiple events per hour and your multiple example works up to line 7 and returns one value.&lt;BR /&gt;
That value isn't from the bucket but from the search time span.&lt;/P&gt;

&lt;P&gt;I appriciate the help.&lt;/P&gt;</description>
    <pubDate>Thu, 07 May 2020 17:58:59 GMT</pubDate>
    <dc:creator>myron12</dc:creator>
    <dc:date>2020-05-07T17:58:59Z</dc:date>
    <item>
      <title>subtract meterRead from Yesterday’s meterRead</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492290#M137326</link>
      <description>&lt;P&gt;My electric meter sends a number but I want to subtract the current from the number an hour ago, so I can chart the usage for each hour.&lt;/P&gt;

&lt;P&gt;My search:&lt;BR /&gt;
source="/home/we/plex/movies/meter.elec" _time=* LastConsumptionCount=*&lt;BR /&gt;
| table _time "LastConsumptionCount"&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 16:19:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492290#M137326</guid>
      <dc:creator>myron12</dc:creator>
      <dc:date>2020-05-07T16:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: subtract meterRead from Yesterday’s meterRead</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492291#M137327</link>
      <description>&lt;P&gt;If you have one event an hour, try &lt;CODE&gt;delta&lt;/CODE&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="/home/we/plex/movies/meter.elec" LastConsumptionCount=*
`comment("Calculate the difference between this event and the previous one")`
| delta LastConsumptionCount as Usage
`comment("Plot the values over time.")`
| timechart span=1h max(Usage) as Usage
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you have multiple events an hour, then this may work better.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="/home/we/plex/movies/meter.elec" LastConsumptionCount=*
`comment("Group events by hour")`
| bucket span=1h _time
`comment("Get the first(min) and last(max) values for each bucket")`
| stats min(LastConsumptionCount) as first, max(LastConsumptionCount) as last by _time
`comment("Hourly use is the difference between the two readings")`
| eval Usage = last- first
| timechart span=1h max(Usage) as Usage
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 May 2020 17:22:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492291#M137327</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-05-07T17:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: subtract meterRead from Yesterday’s meterRead</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492292#M137328</link>
      <description>&lt;P&gt;Assuming your current and the last consumption cound from an hour ago are stored inside the same field called LastConsumptionCount, you can try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="/home/we/plex/movies/meter.elec"  | streamstats current=t time_window=1h window=1 last(LastConsumptionCount) as prev_ConsumptionCount | eval difference = LastConsumptionCount - prev_ConsumptionCount | timechart span=1h max(difference)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 May 2020 17:30:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492292#M137328</guid>
      <dc:creator>shivanshu1593</dc:creator>
      <dc:date>2020-05-07T17:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: subtract meterRead from Yesterday’s meterRead</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492293#M137329</link>
      <description>&lt;P&gt;I do have multiple events per hour and your multiple example works up to line 7 and returns one value.&lt;BR /&gt;
That value isn't from the bucket but from the search time span.&lt;/P&gt;

&lt;P&gt;I appriciate the help.&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 17:58:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492293#M137329</guid>
      <dc:creator>myron12</dc:creator>
      <dc:date>2020-05-07T17:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: subtract meterRead from Yesterday’s meterRead</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492294#M137330</link>
      <description>&lt;P&gt;Critical omission on line 5 fixed.&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 18:33:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492294#M137330</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-05-07T18:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: subtract meterRead from Yesterday’s meterRead</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492295#M137331</link>
      <description>&lt;P&gt;Maybe my problem is that the variable "LastConsumptionCount" is a single number. That is the number that it says on the meter. Not a variable array.&lt;/P&gt;

&lt;P&gt;I store the meter reading every 30 seconds.&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 18:45:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492295#M137331</guid>
      <dc:creator>myron12</dc:creator>
      <dc:date>2020-05-07T18:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: subtract meterRead from Yesterday’s meterRead</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492296#M137332</link>
      <description>&lt;P&gt;Yes that is it.  Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 19:00:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492296#M137332</guid>
      <dc:creator>myron12</dc:creator>
      <dc:date>2020-05-07T19:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: subtract meterRead from Yesterday’s meterRead</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492297#M137333</link>
      <description>&lt;P&gt;The bucket thing works with one problem. &lt;BR /&gt;
So I get one bucket has a first value and a last value.&lt;BR /&gt;
the next bucket first value isn't the same number as the last value of the previous. &lt;/P&gt;

&lt;P&gt;I would like to have the first value subtracted from the previous first value.&lt;/P&gt;

&lt;P&gt;It seams like I am 'going the long way around the barn'. and I would have expected timechart would have a way to handle this.&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 19:55:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492297#M137333</guid>
      <dc:creator>myron12</dc:creator>
      <dc:date>2020-05-07T19:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: subtract meterRead from Yesterday’s meterRead</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492298#M137334</link>
      <description>&lt;P&gt;After reading your comments on Rich's answer, I think I got your requirement. Let's say that you ran this search at 3 PM, and now want to compare the value of &lt;CODE&gt;LastConsumptionCount&lt;/CODE&gt; at 3 PM with it's value, which you got at 2 PM, exactly 1 hour back. Am I correct? If so, then try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="/home/we/plex/movies/meter.elec" earliest=-1h latest=now()  | streamstats current=t time_window=1h window=1 last(LastConsumptionCount) as prev_ConsumptionCount | eval difference = LastConsumptionCount - prev_ConsumptionCount | timechart span=1h max(difference) as difference
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 May 2020 20:46:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtract-meterRead-from-Yesterday-s-meterRead/m-p/492298#M137334</guid>
      <dc:creator>shivanshu1593</dc:creator>
      <dc:date>2020-05-07T20:46:37Z</dc:date>
    </item>
  </channel>
</rss>

