<?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: Stats/Chart count distinct users by Country and eval field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Stats-Chart-count-distinct-users-by-Country-and-eval-field/m-p/238598#M70900</link>
    <description>&lt;P&gt;The temp= line is combining two fields  Country and City ( your can use any name for that matter, I used temp as it's a temporary field). So this way we ran the chart with 3 field grouping (using temp). Once the data is charted, we're using rex command to separate out those combined fields.&lt;/P&gt;</description>
    <pubDate>Thu, 07 Jul 2016 15:07:38 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2016-07-07T15:07:38Z</dc:date>
    <item>
      <title>Stats/Chart count distinct users by Country and eval field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Chart-count-distinct-users-by-Country-and-eval-field/m-p/238594#M70896</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have a query showing the amount of distinct logins by IP address based on the "term" i've created in the query.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats earliest(_time) as first_login latest(_time) as last_login by IP_address User   
| eval term=last_login-first_login   
| eval term=case(term&amp;lt;86400, "Very Short", term&amp;gt;86400 AND term&amp;lt;(86400*7), "Short", term&amp;gt;(86400*7), "Long") 
| chart dc(User) as usercount by IP_address,term
| iplocation IP_address 
| where (isnotnull(Country) AND isnotnull(City) AND NOT Country="United States" AND trim(Country)!="" AND trim(City)!="")
| stats sum("Very Short") AS "Very Short", sum(Short) AS Short, sum(Long) AS Long by Country, City
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After doing some cross-checking, I realized these results are counting multiple values for users if that makes sense. So if "xxx99" had three "Very Short" logins and "xxx90" had 2 "Very Short" logins, its counting it as 5 "Very Short", when in fact I need it to count as 2 (the amount of users that were categorized as Very Short at least once).&lt;/P&gt;

&lt;P&gt;I've tried getting around this myself with this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats earliest(_time) as first_login latest(_time) as last_login by IP_address User   
| eval term=last_login-first_login   
| eval term=case(term&amp;lt;86400, "Very Short", term&amp;gt;86400 AND term&amp;lt;(86400*7), "Short", term&amp;gt;(86400*7), "Long") 
| iplocation IP_address 
| stats dc(User) AS usercount by Country City term
| where (isnotnull(Country) AND isnotnull(City) AND NOT Country="United States" AND trim(Country)!="" AND trim(City)!="")
| search Country=Azerbaijan
| chart sum(usercount) over Country by term
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but with those results, I can't seem to get it to display the Country AND City, not just the City.&lt;/P&gt;

&lt;P&gt;Any thoughts?&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 14:27:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Chart-count-distinct-users-by-Country-and-eval-field/m-p/238594#M70896</guid>
      <dc:creator>zsizemore</dc:creator>
      <dc:date>2016-07-06T14:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: Stats/Chart count distinct users by Country and eval field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Chart-count-distinct-users-by-Country-and-eval-field/m-p/238595#M70897</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats earliest(_time) as first_login latest(_time) as last_login by IP_address User   
 | eval term=last_login-first_login   
 | eval term=case(term&amp;lt;86400, "Very Short", term&amp;gt;86400 AND term&amp;lt;(86400*7), "Short", term&amp;gt;(86400*7), "Long") 
 | iplocation IP_address 
 | where (isnotnull(Country) AND isnotnull(City) AND NOT Country="United States" AND trim(Country)!="" AND trim(City)!="")
 | stats dc(User) AS usercount by Country City term
 | search Country=Azerbaijan | eval temp=Country."##".City
 | chart sum(usercount) over temp by term | rex field=temp "(?&amp;lt;Country&amp;gt;.+)##(?&amp;lt;City&amp;gt;.+)" | table Country, City "Very Short", Short, Long 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jul 2016 17:51:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Chart-count-distinct-users-by-Country-and-eval-field/m-p/238595#M70897</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-07-06T17:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: Stats/Chart count distinct users by Country and eval field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Chart-count-distinct-users-by-Country-and-eval-field/m-p/238596#M70898</link>
      <description>&lt;P&gt;Thanks this seems to work. I changed the order of the first eval to &lt;CODE&gt;eval term=case(term&amp;gt;(86400*7), "Long", term&amp;gt;86400 AND term&amp;lt;(86400*7), "Short", term&amp;lt;86400, "Very Short")&lt;/CODE&gt; so that if a user is identified as Long, they can't also be counted for short/very short.&lt;/P&gt;

&lt;P&gt;I also added a &lt;CODE&gt;dedup User&lt;/CODE&gt; after the stats dc(User) cmd line which looks to do what I've been looking for!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 13:48:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Chart-count-distinct-users-by-Country-and-eval-field/m-p/238596#M70898</guid>
      <dc:creator>zsizemore</dc:creator>
      <dc:date>2016-07-07T13:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Stats/Chart count distinct users by Country and eval field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Chart-count-distinct-users-by-Country-and-eval-field/m-p/238597#M70899</link>
      <description>&lt;P&gt;could I ask what exactly the eval temp= line is doing? I can't seem to find much info about that or the rex cmd how it works.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 13:50:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Chart-count-distinct-users-by-Country-and-eval-field/m-p/238597#M70899</guid>
      <dc:creator>zsizemore</dc:creator>
      <dc:date>2016-07-07T13:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: Stats/Chart count distinct users by Country and eval field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Chart-count-distinct-users-by-Country-and-eval-field/m-p/238598#M70900</link>
      <description>&lt;P&gt;The temp= line is combining two fields  Country and City ( your can use any name for that matter, I used temp as it's a temporary field). So this way we ran the chart with 3 field grouping (using temp). Once the data is charted, we're using rex command to separate out those combined fields.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 15:07:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Chart-count-distinct-users-by-Country-and-eval-field/m-p/238598#M70900</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-07-07T15:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: Stats/Chart count distinct users by Country and eval field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Chart-count-distinct-users-by-Country-and-eval-field/m-p/238599#M70901</link>
      <description>&lt;P&gt;Okay very interesting, i'm learning a lot still. Is there a way to display this with geostats?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 19:56:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Chart-count-distinct-users-by-Country-and-eval-field/m-p/238599#M70901</guid>
      <dc:creator>zsizemore</dc:creator>
      <dc:date>2016-07-07T19:56:29Z</dc:date>
    </item>
  </channel>
</rss>

