<?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 How to convert a dollar amount field with $ sign, commas and decimals to a number so I can do avg or sum, etc.? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-dollar-amount-field-with-sign-commas-and/m-p/48404#M11552</link>
    <description>&lt;P&gt;latest funciton works but avg function does not. I believe splunk is treating my  Amount field as a text string. Any way to convert a dollar amount to a numeric value?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Rob&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Working:
sourcetype="financials-2" | stats latest(Amount) by Account

    Account     latest(Amount)
1   Advertising $232.62
2   Annual Report   $10.00
3   Electric    $367.73
4   Gazebo Maintenance  $660.00
5   General Maintenance $1,200.00
6   Insurance   $1,638.00
7   Lawn Maint - Extra  $9,200.00
8   Lawn Maintenance    $1,331.00
9   Legal   $231.25
10  Mailing Supplies    $54.62

Not working - returns null values for avg(Amount): 
sourcetype="financials-2" | stats avg(Amount) by Account
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 27 Aug 2013 19:41:33 GMT</pubDate>
    <dc:creator>bandit</dc:creator>
    <dc:date>2013-08-27T19:41:33Z</dc:date>
    <item>
      <title>How to convert a dollar amount field with $ sign, commas and decimals to a number so I can do avg or sum, etc.?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-dollar-amount-field-with-sign-commas-and/m-p/48404#M11552</link>
      <description>&lt;P&gt;latest funciton works but avg function does not. I believe splunk is treating my  Amount field as a text string. Any way to convert a dollar amount to a numeric value?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Rob&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Working:
sourcetype="financials-2" | stats latest(Amount) by Account

    Account     latest(Amount)
1   Advertising $232.62
2   Annual Report   $10.00
3   Electric    $367.73
4   Gazebo Maintenance  $660.00
5   General Maintenance $1,200.00
6   Insurance   $1,638.00
7   Lawn Maint - Extra  $9,200.00
8   Lawn Maintenance    $1,331.00
9   Legal   $231.25
10  Mailing Supplies    $54.62

Not working - returns null values for avg(Amount): 
sourcetype="financials-2" | stats avg(Amount) by Account
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Aug 2013 19:41:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-dollar-amount-field-with-sign-commas-and/m-p/48404#M11552</guid>
      <dc:creator>bandit</dc:creator>
      <dc:date>2013-08-27T19:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a dollar amount field with $ sign, commas and decimals to a number so I can do avg or sum, etc.?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-dollar-amount-field-with-sign-commas-and/m-p/48405#M11553</link>
      <description>&lt;P&gt;Strip all the non-numerical characters out 1st. Splunk is treating the values as a string, not a number.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="financials-2" 
| rex mode=sed field=Amount "s/[^\d\.-]//g"
| stats avg(Amount) as AvgAmount by Account
| eval AvgAmount=if(AvgAmount &amp;lt; 0, "-$".trim(AvgAmount,"-"),"$".AvgAmount)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The last line just reintroduces the $ symbol.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2013 21:14:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-dollar-amount-field-with-sign-commas-and/m-p/48405#M11553</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-08-27T21:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a dollar amount field with $ sign, commas and decimals to a number so I can do avg or sum, etc.?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-dollar-amount-field-with-sign-commas-and/m-p/48406#M11554</link>
      <description>&lt;P&gt;I &lt;EM&gt;think&lt;/EM&gt; you should keep the decimal dot. Otherwise you'll end up with the the wrong figures.&lt;/P&gt;

&lt;P&gt;I suggest the slightly simpler;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;... | eval Amt = substr(Amount,2) | convert rmcomma(Amt) | stats avg(Amt) by Account&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;EDIT: my bad. you did keep it. ... and I didn't remove the comma....&lt;/P&gt;

&lt;P&gt;EDIT2: updated above, now without commas.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2013 21:24:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-dollar-amount-field-with-sign-commas-and/m-p/48406#M11554</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-08-27T21:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a dollar amount field with $ sign, commas and decimals to a number so I can do avg or sum, etc.?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-dollar-amount-field-with-sign-commas-and/m-p/48407#M11555</link>
      <description>&lt;P&gt;&lt;CODE&gt;Amt = substr(Amount,2)&lt;/CODE&gt;  keeps the $ if the value is negative.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2013 11:18:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-dollar-amount-field-with-sign-commas-and/m-p/48407#M11555</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-08-28T11:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a dollar amount field with $ sign, commas and decimals to a number so I can do avg or sum, etc.?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-dollar-amount-field-with-sign-commas-and/m-p/48408#M11556</link>
      <description>&lt;P&gt;This works great, however in simple xml, Splunk doesn't like the &amp;lt;.  I am getting this error message - Encountered the following error while trying to update: In handler 'views': Error parsing XML on line 67: StartTag: invalid element name.  Am I missing something?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Aug 2014 15:18:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-dollar-amount-field-with-sign-commas-and/m-p/48408#M11556</guid>
      <dc:creator>_gkollias</dc:creator>
      <dc:date>2014-08-06T15:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a dollar amount field with $ sign, commas and decimals to a number so I can do avg or sum, etc.?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-dollar-amount-field-with-sign-commas-and/m-p/48409#M11557</link>
      <description>&lt;P&gt;Put your search query within &amp;lt;![CDATA[ your search query here ]]&amp;gt; tag. Alternatively, replace '&amp;lt;' with "&amp;amp;lt;".&lt;/P&gt;</description>
      <pubDate>Wed, 06 Aug 2014 15:24:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-dollar-amount-field-with-sign-commas-and/m-p/48409#M11557</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-08-06T15:24:56Z</dc:date>
    </item>
  </channel>
</rss>

