<?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: Manipulating Table Rows of Sensor Data to Shift _time in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Manipulating-Table-Rows-of-Sensor-Data-to-Shift-time/m-p/268090#M80645</link>
    <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* ItemID OR Speed OR Sensor* 
 | bin _time span=1m 
 | stats avg(Measurement) as Measurement by _time, FieldName
 | table * 
 | xyseries _time FieldName Measurement 
 | filldown * 
 | eval timeshift=(##/Speed)*60
 | eval temp=_time."#".timeshift
 | fields - _time timeshift
 | untable temp FieldName Measurement
 | eval _time=mvindex(split(temp,"#"),0)
 | eval timeshift=mvindex(split(temp,"#"),1) | fields - temp
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 02 Feb 2017 15:57:02 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2017-02-02T15:57:02Z</dc:date>
    <item>
      <title>Manipulating Table Rows of Sensor Data to Shift _time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Manipulating-Table-Rows-of-Sensor-Data-to-Shift-time/m-p/268089#M80644</link>
      <description>&lt;P&gt;&lt;STRONG&gt;tl;dr : Need to manipulate rows / cols of a table in a specific way to avoid using subsearch, can't figure out how. Scroll to bottom and look at tables.&lt;/STRONG&gt; &lt;/P&gt;

&lt;P&gt;I'm working with some sensor data and I'd like to "shift" _time for some events, so that they are correctly correlated with an appropriate ItemID. I have previously done this with a subsearch (which I'll include below) but I'm trying to get rid of the subsearch because of it's limitations. &lt;/P&gt;

&lt;P&gt;Here are the fields present in the data: &lt;BR /&gt;
_time FieldName Value &lt;/P&gt;

&lt;P&gt;There's a field called ItemID which identifies when the item is entering the processing queue. The queue runs at Speed. Some amount of time later, based on Speed and a fixed distance, the item of interest passes under the Sensors, (up to 100s). The raw data does not include the _time that an item is under these sensors, but it can be calculated with an equation from the Speed and the distance. &lt;/P&gt;

&lt;P&gt;Here's the subsearch spl: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* Speed ItemID 
| timechart span=1m avg(Measurement) by FieldName 
| filldown 
| timeshift=(##/Speed)*60 
| append [ search SensorA | timechart avg(Measurement) span=1m | filldown | table _time Measurement FieldName ] 
| sort _time 
| filldown timeshift 
| eval _time=if(FieldName==SensorA,_time-timeshift,_time)
| sort _time 
| filldown Measurement 
| rename Measurement as SensorA 
| stats avg(SensorA) by ItemID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This search works because you have two sets of _time, one you're shifting by subtracting the shift (SensorA) and one you're not. However, when you get a large number of sensors over a longer period of time, the limitations of subsearch come into play. &lt;/P&gt;

&lt;P&gt;Here's the new search, which eliminates subsearch: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* ItemID OR Speed OR Sensor* 
| bin _time span=1m 
| stats avg(Measurement) as Measurement by _time, FieldName
| table * 
| xyseries _time FieldName Measurement 
| filldown * 
| eval timeshift=(##/Speed)*60
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This search produces a table with records that look like this: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time   ItemID               timeshift   SensorA   SensorB   SensorC
8:00     9385723423          3333333     33.3      33.3      33.3 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I'd like to do is create a table like this: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time       FieldName           Measurement             timeshift
8:00         ItemID                9385723423             3333333
8:00         SensorA                33.3                  3333333
8:00         SensorB                33.3                  3333333
8:00         SensorC                33.3                  3333333
8:00         SensorD                33.3                  3333333
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can then manipulate this table to timeshift only the sensor data, xyseries everything to put it back together, and use stats against the results. &lt;/P&gt;

&lt;P&gt;Any advice? I've looked at untable docs &amp;amp; examples but I think it only handles 3 fields, and I need timeshift to stay on every sensor record.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 14:27:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Manipulating-Table-Rows-of-Sensor-Data-to-Shift-time/m-p/268089#M80644</guid>
      <dc:creator>ErikaE</dc:creator>
      <dc:date>2017-02-02T14:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating Table Rows of Sensor Data to Shift _time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Manipulating-Table-Rows-of-Sensor-Data-to-Shift-time/m-p/268090#M80645</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* ItemID OR Speed OR Sensor* 
 | bin _time span=1m 
 | stats avg(Measurement) as Measurement by _time, FieldName
 | table * 
 | xyseries _time FieldName Measurement 
 | filldown * 
 | eval timeshift=(##/Speed)*60
 | eval temp=_time."#".timeshift
 | fields - _time timeshift
 | untable temp FieldName Measurement
 | eval _time=mvindex(split(temp,"#"),0)
 | eval timeshift=mvindex(split(temp,"#"),1) | fields - temp
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Feb 2017 15:57:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Manipulating-Table-Rows-of-Sensor-Data-to-Shift-time/m-p/268090#M80645</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-02-02T15:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating Table Rows of Sensor Data to Shift _time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Manipulating-Table-Rows-of-Sensor-Data-to-Shift-time/m-p/268091#M80646</link>
      <description>&lt;P&gt;This solution works great! It appears to run quickly and efficiently, and doesn't introduce any limitations based on the commands used. &lt;/P&gt;

&lt;P&gt;Many thanks! Folks like you make the splunk community great. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;

&lt;P&gt;Another option I realized is to use timechart avg(*) as * span=30s to create "empty" buckets in between the 1 min buckets which were previously created. Timechart also imposes limitations though, so it's not as flexible as your solution.   &lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 18:40:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Manipulating-Table-Rows-of-Sensor-Data-to-Shift-time/m-p/268091#M80646</guid>
      <dc:creator>ErikaE</dc:creator>
      <dc:date>2017-02-02T18:40:10Z</dc:date>
    </item>
  </channel>
</rss>

