<?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: How to show all current day transactions whose amount is higher than the previous month average in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-show-all-current-day-transactions-whose-amount-is-higher/m-p/465449#M131135</link>
    <description>&lt;P&gt;@woodcock  I tried to do that, but it also doesn't work: Error in 'where' command: The expression is malformed. A comparison term is missing.&lt;BR /&gt;
I have 600 000 events/transactions (and at least 100 000 different customers) and I have to search for all who satisfy the condition (all transactions of the current day whose amount is higher than the average transaction amount for this customer for the previous month), not one by one (NOT specifying exact customer and then searching only for him).&lt;/P&gt;</description>
    <pubDate>Sun, 15 Dec 2019 12:38:28 GMT</pubDate>
    <dc:creator>dorismustovic</dc:creator>
    <dc:date>2019-12-15T12:38:28Z</dc:date>
    <item>
      <title>How to show all current day transactions whose amount is higher than the previous month average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-show-all-current-day-transactions-whose-amount-is-higher/m-p/465446#M131132</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I have a bank transaction XML log with DATE, CC, AMOUNT. I need to show all transactions of the current day whose amount is higher than the average transaction amount for this customer for the previous month.&lt;BR /&gt;
Here is the log example:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/8087iBC6C4900497C0618/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I found one similar topic and tried this so far, but it doesn't work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  eval epochtime=strptime(DATE, "%d%m%Y")  | where epochtime=relative_time(epochtime, "-1mon@mon")&amp;lt;=epochtime| eval date=strftime(epochtime, "%d-%m-%Y") |eval cardmask=substr(CC, 0,4)+"******" | eval cardmask1=substr(CC, 11,12) | eval mask=cardmask+cardmask1| stats sum(AMOUNT) as TodaySum by mask | appendcols [ search sourcetype="..." |xmlkv |  eval epochtime=strptime(Date, "%d%m%y")  | where epochtime=relative_time(epochtime, "@d")&amp;lt;=epochtime  AND relative_time(epochtime, "-1mon@mon")&amp;lt;=epochtime | eval date=strftime(epochtime, "%d-%m-%Y") |eval cardmask=substr(CC, 0,4)+"******" | eval cardmask1=substr(CC, 11,12) | eval mask=cardmask+cardmask1| stats avg(AMOUNT) as LastMonthAvg by mask ]  eval alert=if(TodaySum  &amp;gt; LastMonthAvg, "OK","NOK")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please, I need help, got no more ideas.&lt;/P&gt;

&lt;P&gt;Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 21:49:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-show-all-current-day-transactions-whose-amount-is-higher/m-p/465446#M131132</guid>
      <dc:creator>dorismustovic</dc:creator>
      <dc:date>2019-12-12T21:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to show all current day transactions whose amount is higher than the previous month average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-show-all-current-day-transactions-whose-amount-is-higher/m-p/465447#M131133</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="&amp;lt;DATE&amp;gt;11122019&amp;lt;/DATE&amp;gt;
&amp;lt;TIME&amp;gt;000031&amp;lt;/TIME&amp;gt;
&amp;lt;CC&amp;gt;2615710116889328&amp;lt;/CC&amp;gt;
&amp;lt;AMOUNT&amp;gt;14972.19&amp;lt;/AMOUNT&amp;gt;"
| appendpipe
    [| eval _raw="&amp;lt;DATE&amp;gt;10122019&amp;lt;/DATE&amp;gt;
&amp;lt;TIME&amp;gt;000031&amp;lt;/TIME&amp;gt;
&amp;lt;CC&amp;gt;2615710116889328&amp;lt;/CC&amp;gt;
&amp;lt;AMOUNT&amp;gt;14972.19&amp;lt;/AMOUNT&amp;gt;"]
| appendpipe
    [| eval _raw="&amp;lt;DATE&amp;gt;10112019&amp;lt;/DATE&amp;gt;
&amp;lt;TIME&amp;gt;000031&amp;lt;/TIME&amp;gt;
&amp;lt;CC&amp;gt;2615710116889328&amp;lt;/CC&amp;gt;
&amp;lt;AMOUNT&amp;gt;14972.19&amp;lt;/AMOUNT&amp;gt;"]
| appendpipe
    [| eval _raw="&amp;lt;DATE&amp;gt;09112019&amp;lt;/DATE&amp;gt;
&amp;lt;TIME&amp;gt;000031&amp;lt;/TIME&amp;gt;
&amp;lt;CC&amp;gt;2615710116889328&amp;lt;/CC&amp;gt;
&amp;lt;AMOUNT&amp;gt;14972.19&amp;lt;/AMOUNT&amp;gt;"]
`comment("the logic is blow")`
| xmlkv 
| eval epochtime=strptime(DATE, "%d%m%Y")
| eval Month_date=tonumber(strftime(epochtime,"%m"))
| eval cardmask=substr(CC, 0,4)+"******" 
| eval cardmask1=substr(CC, 11,12) 
| eval mask=cardmask+cardmask1 
| eventstats sum(AMOUNT) as TodaySum by mask epochtime
| eventstats avg(TodaySum) as Month_avg by mask Month_date
| table epochtime mask TodaySum Month_avg Month_date
| rename epochtime as _time
| eventstats values(eval(if(tonumber(strftime(now(),"%m")) -1 == Month_date,Month_avg,NULL))) as prev_Mon_avg by mask
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It wasn't actual data, so I could only do this.&lt;BR /&gt;
please try with &lt;CODE&gt;earliest=-1month@month&lt;/CODE&gt; and your search.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 04:47:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-show-all-current-day-transactions-whose-amount-is-higher/m-p/465447#M131133</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-12-14T04:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to show all current day transactions whose amount is higher than the previous month average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-show-all-current-day-transactions-whose-amount-is-higher/m-p/465448#M131134</link>
      <description>&lt;P&gt;First of all, FIX YOUR TIMESTAMP SETTINGS so that &lt;CODE&gt;_time&lt;/CODE&gt; is correct, then do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=Myindex sourcetype="Mysourcetype" earliest=@d latest=now
|eval cardmask=substr(CC, 0,4) . "**" 
| eval cardmask1=substr(CC, 11,12) 
| eval maskCC=cardmask+cardmask1
| eval AVG = [search index=Myindex sourcetype="Mysourcetype" earliest=-1mon@mon latest=@mon | stats avg(AMOUNT) as avg | return $avg ]
| where AMOUNT &amp;gt; AVG
| table *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Dec 2019 18:13:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-show-all-current-day-transactions-whose-amount-is-higher/m-p/465448#M131134</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-14T18:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to show all current day transactions whose amount is higher than the previous month average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-show-all-current-day-transactions-whose-amount-is-higher/m-p/465449#M131135</link>
      <description>&lt;P&gt;@woodcock  I tried to do that, but it also doesn't work: Error in 'where' command: The expression is malformed. A comparison term is missing.&lt;BR /&gt;
I have 600 000 events/transactions (and at least 100 000 different customers) and I have to search for all who satisfy the condition (all transactions of the current day whose amount is higher than the average transaction amount for this customer for the previous month), not one by one (NOT specifying exact customer and then searching only for him).&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2019 12:38:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-show-all-current-day-transactions-whose-amount-is-higher/m-p/465449#M131135</guid>
      <dc:creator>dorismustovic</dc:creator>
      <dc:date>2019-12-15T12:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to show all current day transactions whose amount is higher than the previous month average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-show-all-current-day-transactions-whose-amount-is-higher/m-p/465450#M131136</link>
      <description>&lt;P&gt;Actually it worked with this one:&lt;/P&gt;

&lt;P&gt;index=Myindex sourcetype="Mysourcetype" earliest=@d latest=now |eval cardmask=substr(CC, 0,4)+"******" | eval cardmask1=substr(CC, 11,12) | eval maskCC=cardmask+cardmask1| where AMOUNT&amp;gt; [search index=Myindex sourcetype="Mysourcetype" earliest=-1mon@mon latest=@mon | stats avg(AMOUNT) as avg | return $avg ] | table *&lt;/P&gt;

&lt;P&gt;It works perfectly, but can You please tell me how to show average in my table also (now it shows maskCC and current day AMOUNT, but I would like to show last month average also)? &lt;/P&gt;

&lt;P&gt;Thank You in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2019 14:01:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-show-all-current-day-transactions-whose-amount-is-higher/m-p/465450#M131136</guid>
      <dc:creator>dorismustovic</dc:creator>
      <dc:date>2019-12-15T14:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to show all current day transactions whose amount is higher than the previous month average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-show-all-current-day-transactions-whose-amount-is-higher/m-p/465451#M131137</link>
      <description>&lt;P&gt;See updated answer above.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2019 15:22:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-show-all-current-day-transactions-whose-amount-is-higher/m-p/465451#M131137</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-15T15:22:01Z</dc:date>
    </item>
  </channel>
</rss>

