<?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 calculate percent from distinct count? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percent-from-distinct-count/m-p/246047#M73370</link>
    <description>&lt;P&gt;How about this?  Add up the total using eventstats and then calculate the percentage for each row.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-500 | eval session_id=random() % 500 | eval device_id = random() % 10 | stats dc(session_id) AS unique_sessions by device_id | eventstats sum(unique_sessions) AS total | eval percent=round((unique_sessions/total)*100,2) | table device_id unique_sessions percent
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 11 May 2016 15:29:21 GMT</pubDate>
    <dc:creator>Jeremiah</dc:creator>
    <dc:date>2016-05-11T15:29:21Z</dc:date>
    <item>
      <title>How to calculate percent from distinct count?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percent-from-distinct-count/m-p/246046#M73369</link>
      <description>&lt;P&gt;I'm aware of a number of questions on here dealing with percents, including: &lt;A href="https://answers.splunk.com/answers/120424/how-to-display-percentage-of-total.html"&gt;https://answers.splunk.com/answers/120424/how-to-display-percentage-of-total.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;But I can't figure out how to apply it to my question. &lt;/P&gt;

&lt;P&gt;I have browser logs of site sessions, and want to report the % breakdown by device type. &lt;/P&gt;

&lt;P&gt;This search gets me a table of device totals (by distinct sessions), but how do i make it a %?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=pageactions tag=external_traffic session_id=*
| fillnull value=blank devicetype
| stats dc(session_id) as unique_sessions by devicetype
| table devicetype unique_sessions
| addtotals row=f col=t labelfield=devicetype label=total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Actually, ideally I'd like to have two columns (both as %) showing the % of distinct events and the % of all events. That way I can see both what device our visitors are using and if one device is causing more traffic.&lt;/P&gt;

&lt;P&gt;I can do that from here (if i could just divide by total)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=pageactions tag=external_traffic session_id=*
| fillnull value=blank devicetype
| stats dc(session_id) as unique_sessions, count as event_counts by devicetype
| table devicetype unique_sessions event_counts 
| addtotals row=f col=t labelfield=devicetype label=total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 May 2016 15:20:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percent-from-distinct-count/m-p/246046#M73369</guid>
      <dc:creator>ra01</dc:creator>
      <dc:date>2016-05-11T15:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate percent from distinct count?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percent-from-distinct-count/m-p/246047#M73370</link>
      <description>&lt;P&gt;How about this?  Add up the total using eventstats and then calculate the percentage for each row.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-500 | eval session_id=random() % 500 | eval device_id = random() % 10 | stats dc(session_id) AS unique_sessions by device_id | eventstats sum(unique_sessions) AS total | eval percent=round((unique_sessions/total)*100,2) | table device_id unique_sessions percent
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 May 2016 15:29:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percent-from-distinct-count/m-p/246047#M73370</guid>
      <dc:creator>Jeremiah</dc:creator>
      <dc:date>2016-05-11T15:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate percent from distinct count?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percent-from-distinct-count/m-p/246048#M73371</link>
      <description>&lt;P&gt;whoa! thanks. &lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 15:33:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percent-from-distinct-count/m-p/246048#M73371</guid>
      <dc:creator>ra01</dc:creator>
      <dc:date>2016-05-11T15:33:47Z</dc:date>
    </item>
  </channel>
</rss>

