<?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: Combining &amp;quot;stats dc(x)&amp;quot; with &amp;quot;stats dc(x) by y&amp;quot; in same search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Combining-quot-stats-dc-x-quot-with-quot-stats-dc-x-by-y-quot-in/m-p/55310#M13498</link>
    <description>&lt;P&gt;UPDATED: &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;eventtype=visit | stats count by city person | eventstats dc(person) as totalPeople | stats dc(person) as visitors last(totalPeople) as totalPeople by city | eval percentage=100*(visitors/totalPeople) | table city percentage&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Mar 2013 05:59:41 GMT</pubDate>
    <dc:creator>sideview</dc:creator>
    <dc:date>2013-03-08T05:59:41Z</dc:date>
    <item>
      <title>Combining "stats dc(x)" with "stats dc(x) by y" in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-quot-stats-dc-x-quot-with-quot-stats-dc-x-by-y-quot-in/m-p/55309#M13497</link>
      <description>&lt;P&gt;I am having a ton of trouble expressing this query.&lt;/P&gt;

&lt;P&gt;Suppose I have 1,000 distinct people, and 25 cities. Over a time period, each person might visit [0...n] cities.&lt;/P&gt;

&lt;P&gt;I want a report which shows, for each city, what percentage of my unique people visited that city? Note that in this report, the percentages won't add up to 100%, since any person might visit more than one city in the time period.&lt;/P&gt;

&lt;P&gt;This search gives me the # of unique people and returns one row, value of "1000":&lt;/P&gt;

&lt;PRE&gt;eventtype=visit |stats dc(person) | rename dc(person) as "# Unique People"&lt;/PRE&gt;

&lt;P&gt;This search shows # of unique people who visited each city and returns 25 rows:&lt;/P&gt;

&lt;PRE&gt;eventtype=visit |stats dc(person) by city | rename dc(person) as "# Unique People" | sort -"# Unique People"&lt;/PRE&gt;

&lt;P&gt;What I want is, in Search #2, instead of showing a # of people, I want to show the # of people divided by the total returned in Search #1 (which would be a percentage of the total unique people).&lt;/P&gt;

&lt;P&gt;Can anyone help? I've played with append, appendcols, join, appendpipe.. I'm lost.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2013 03:12:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-quot-stats-dc-x-quot-with-quot-stats-dc-x-by-y-quot-in/m-p/55309#M13497</guid>
      <dc:creator>bryanfe</dc:creator>
      <dc:date>2013-03-08T03:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Combining "stats dc(x)" with "stats dc(x) by y" in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-quot-stats-dc-x-quot-with-quot-stats-dc-x-by-y-quot-in/m-p/55310#M13498</link>
      <description>&lt;P&gt;UPDATED: &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;eventtype=visit | stats count by city person | eventstats dc(person) as totalPeople | stats dc(person) as visitors last(totalPeople) as totalPeople by city | eval percentage=100*(visitors/totalPeople) | table city percentage&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2013 05:59:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-quot-stats-dc-x-quot-with-quot-stats-dc-x-by-y-quot-in/m-p/55310#M13498</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2013-03-08T05:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: Combining "stats dc(x)" with "stats dc(x) by y" in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-quot-stats-dc-x-quot-with-quot-stats-dc-x-by-y-quot-in/m-p/55311#M13499</link>
      <description>&lt;P&gt;Thank you. I tried this, but the "totalPeople" column ends up empty. Not sure why.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2013 06:22:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-quot-stats-dc-x-quot-with-quot-stats-dc-x-by-y-quot-in/m-p/55311#M13499</guid>
      <dc:creator>bryanfe</dc:creator>
      <dc:date>2013-03-08T06:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Combining "stats dc(x)" with "stats dc(x) by y" in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-quot-stats-dc-x-quot-with-quot-stats-dc-x-by-y-quot-in/m-p/55312#M13500</link>
      <description>&lt;P&gt;totalPeople ends up empty because the first stats drops the person field, you need to swap things around a bit.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eventstats dc(person) as totalPeople | stats dc(person) as uniquePeople values(totalPeople) as totalPeople by city | eval percentage = 100*(uniquePeople/totalPeople)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Mar 2013 08:31:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-quot-stats-dc-x-quot-with-quot-stats-dc-x-by-y-quot-in/m-p/55312#M13500</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-03-08T08:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: Combining "stats dc(x)" with "stats dc(x) by y" in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-quot-stats-dc-x-quot-with-quot-stats-dc-x-by-y-quot-in/m-p/55313#M13501</link>
      <description>&lt;P&gt;Oops. I see the problem. I'll update.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2013 18:12:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-quot-stats-dc-x-quot-with-quot-stats-dc-x-by-y-quot-in/m-p/55313#M13501</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2013-03-08T18:12:36Z</dc:date>
    </item>
  </channel>
</rss>

