<?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: Foreach for multivalue variable in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Foreach-for-multivalue-variable/m-p/366035#M160498</link>
    <description>&lt;P&gt;Thx for reply!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="dynavision"
| spath
| eval EXAM_TYPE = ...
| eval PATIENT_ID = ...
| rex max_match=0 "\"rt[\d]+\":\s\"(?&amp;lt;RT&amp;gt;[\d\.]+)\""
| mvexpand(RT)
| stats avg(RT) as AVG_RT by _time PATIENT_ID EXAM_TYPE
| eval AVG_RT = round(AVG_RT, 2)
| sort _time
| table _time PATIENT_ID EXAM_TYPE AVG_RT

2016-02-29 04:25:00 998097  *A  1.90
2016-02-29 04:26:32 998097  programm stradaniy levoi ruki 2 1.60
2016-02-29 04:28:34 998097  *B 1 Sec Fast   0.74
2016-02-29 05:15:38 762888  *A  2.06
2016-02-29 05:17:15 762888  *B 1 Sec Fast   0.83
2016-02-29 05:19:01 762888  programm stradaniy levoi ruki   2.06
2016-02-29 06:11:04 547662  small1  2.04
2016-02-29 06:13:14 547662  small1  1.61
2016-02-29 06:17:44 547662  8   1.80
2016-03-03 08:20:20 221439  *A  0.98
2016-03-03 08:22:14 221439  programm stradaniy levoi ruki   1.21
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need chart: average reaction time by session for each exam_type. Session is serial number each day of exam. For expl:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; SESSION       _time           PATIENT_ID EXAM_TYPE
 1             2016-01-01      1          A
 2             2016-01-03      1          A
 1             2016-01-03      2          A
 2             2016-01-05      2          A
 1             2016-01-07      1          B
 2             2016-01-08      1          B
 3             2016-01-11      1          A
 3             2016-01-12      2          A
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 30 Jun 2017 09:57:19 GMT</pubDate>
    <dc:creator>yurykiselev</dc:creator>
    <dc:date>2017-06-30T09:57:19Z</dc:date>
    <item>
      <title>Foreach for multivalue variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-for-multivalue-variable/m-p/366032#M160495</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time | id | exam_type | avg_reaction_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Patients pass several types of exams (exam_a, exam_b, exam_c...). Exams that take place in one day considered as one session.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval DAY = strftime(_time, "%Y%m%d")
| stats avg(avg_reaction_time) as AVG_RT_DAY by DAY
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm trying to get a chart of avg_reaction_times (Abscissa) for an individual exam_type by sessions (Ordinate) for defined exam types.&lt;BR /&gt;
Having variable EXAM_TYPE_REQ = "exam_a exam_b exam_c" (getting from form) I thought about &lt;EM&gt;foreach&lt;/EM&gt; for each of them.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:36:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-for-multivalue-variable/m-p/366032#M160495</guid>
      <dc:creator>yurykiselev</dc:creator>
      <dc:date>2020-09-29T14:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach for multivalue variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-for-multivalue-variable/m-p/366033#M160496</link>
      <description>&lt;P&gt;So if your multivalue variable is an input in the form used to filter what to report with a space delimiter, then you need to make it a multivalue and format it on the search.. let me explain with a simple query..&lt;/P&gt;

&lt;P&gt;index=foo sourcetype=bar ([stats count | head 1 | eval exam_type= "$EXAM_TYPE_REQ$" | makemv exam_type delim=" " | mvexpand exam_type | fields exam_type | table exam_type | format]) | eval DAY = strftime(_time, "%Y%m%d") | stats avg(avg_reaction_time) as AVG_RT_DAY by DAY, exam_type &lt;/P&gt;

&lt;P&gt;So my strategy would be to first get whatever events we need filtered by a multivalue input from search command, then do the analysis you need to do.&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Rafael.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:36:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-for-multivalue-variable/m-p/366033#M160496</guid>
      <dc:creator>rafaelsalazar</dc:creator>
      <dc:date>2020-09-29T14:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach for multivalue variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-for-multivalue-variable/m-p/366034#M160497</link>
      <description>&lt;P&gt;Show your events (or the modified events at the point where things break down) and your desired output.  I am lost.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 22:27:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-for-multivalue-variable/m-p/366034#M160497</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-06-29T22:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach for multivalue variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-for-multivalue-variable/m-p/366035#M160498</link>
      <description>&lt;P&gt;Thx for reply!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="dynavision"
| spath
| eval EXAM_TYPE = ...
| eval PATIENT_ID = ...
| rex max_match=0 "\"rt[\d]+\":\s\"(?&amp;lt;RT&amp;gt;[\d\.]+)\""
| mvexpand(RT)
| stats avg(RT) as AVG_RT by _time PATIENT_ID EXAM_TYPE
| eval AVG_RT = round(AVG_RT, 2)
| sort _time
| table _time PATIENT_ID EXAM_TYPE AVG_RT

2016-02-29 04:25:00 998097  *A  1.90
2016-02-29 04:26:32 998097  programm stradaniy levoi ruki 2 1.60
2016-02-29 04:28:34 998097  *B 1 Sec Fast   0.74
2016-02-29 05:15:38 762888  *A  2.06
2016-02-29 05:17:15 762888  *B 1 Sec Fast   0.83
2016-02-29 05:19:01 762888  programm stradaniy levoi ruki   2.06
2016-02-29 06:11:04 547662  small1  2.04
2016-02-29 06:13:14 547662  small1  1.61
2016-02-29 06:17:44 547662  8   1.80
2016-03-03 08:20:20 221439  *A  0.98
2016-03-03 08:22:14 221439  programm stradaniy levoi ruki   1.21
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need chart: average reaction time by session for each exam_type. Session is serial number each day of exam. For expl:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; SESSION       _time           PATIENT_ID EXAM_TYPE
 1             2016-01-01      1          A
 2             2016-01-03      1          A
 1             2016-01-03      2          A
 2             2016-01-05      2          A
 1             2016-01-07      1          B
 2             2016-01-08      1          B
 3             2016-01-11      1          A
 3             2016-01-12      2          A
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jun 2017 09:57:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-for-multivalue-variable/m-p/366035#M160498</guid>
      <dc:creator>yurykiselev</dc:creator>
      <dc:date>2017-06-30T09:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach for multivalue variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-for-multivalue-variable/m-p/366036#M160499</link>
      <description>&lt;P&gt;If I understand you correctly (which is by not means likely), like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval raw="2016-02-29 04:25:00    998097    *A    1.90
2016-02-29 04:26:32    998097    programm stradaniy levoi ruki 2    1.60
2016-02-29 04:28:34    998097    *B 1 Sec Fast    0.74
2016-02-29 05:15:38    762888    *A    2.06
2016-02-29 05:17:15    762888    *B 1 Sec Fast    0.83
2016-02-29 05:19:01    762888    programm stradaniy levoi ruki    2.06
2016-02-29 06:11:04    547662    small1    2.04
2016-02-29 06:13:14    547662    small1    1.61
2016-02-29 06:17:44    547662    8    1.80
2016-03-03 08:20:20    221439    *A    0.98
2016-03-03 08:22:14    221439    programm stradaniy levoi ruki    1.21"
| makemv delim="
" raw
| mvexpand raw
| rename raw AS _raw
| rex "^(?&amp;lt;_time&amp;gt;\S+\s+\S+)\s+(?&amp;lt;PATIENT_ID&amp;gt;\S+)\s+(?&amp;lt;EXAM_TYPE&amp;gt;.*?)\s+(?&amp;lt;AVG_RT&amp;gt;\S+)$"
| eval _time = strptime(_time, "%Y-%m-%d %H:%M:%S")

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| bin span=1d _time
| stats avg(AVG_RT) AS AVG_RT BY _time EXAM_TYPE PATIENT_ID
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jun 2017 15:27:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-for-multivalue-variable/m-p/366036#M160499</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-06-30T15:27:36Z</dc:date>
    </item>
  </channel>
</rss>

