<?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 do I use the stats command on a field value that has duplicate entries? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394905#M114706</link>
    <description>&lt;P&gt;@johnward4&lt;/P&gt;

&lt;P&gt;Is it ok if you display all transactions and Total?  Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=businesstrans  customer=* 
| eventstats sum(unit_price) as Transaction_Total by customer, _date
| table _date, customer, item_id, Description, quantity, unit_price, Transaction_Total
| sort - Transaction_Total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 28 Sep 2018 04:32:52 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2018-09-28T04:32:52Z</dc:date>
    <item>
      <title>How do I use the stats command on a field value that has duplicate entries?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394904#M114705</link>
      <description>&lt;P&gt;I'm trying to table sales data and would like to have my quantity field values to calculate the total number that the item_id shows in a single transaction.  &lt;/P&gt;

&lt;P&gt;Example : Let's say a customer buys 3 apples with the same item_id, 2 oranges w/ the same item_id and one banana.  I would like to know how to blend a stats for Quantity of each item_id in the transaction so they don't show all three apples in the transaction on their own line in my stats list or values(item_id).  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;![index=businesstrans  customer=*
| stats list(item_id) as item_id, list(description) as Description, list(quantity) as quantity, list(unit_price) as unit_price, sum(unit_price) as Transaction_Total by customer, _date
| table _date, customer, item_id, Description, quantity, unit_price, Transaction_Total
| sort - Transaction_Total][1]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:24:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394904#M114705</guid>
      <dc:creator>johnward4</dc:creator>
      <dc:date>2020-09-29T21:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use the stats command on a field value that has duplicate entries?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394905#M114706</link>
      <description>&lt;P&gt;@johnward4&lt;/P&gt;

&lt;P&gt;Is it ok if you display all transactions and Total?  Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=businesstrans  customer=* 
| eventstats sum(unit_price) as Transaction_Total by customer, _date
| table _date, customer, item_id, Description, quantity, unit_price, Transaction_Total
| sort - Transaction_Total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Sep 2018 04:32:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394905#M114706</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2018-09-28T04:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use the stats command on a field value that has duplicate entries?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394906#M114707</link>
      <description>&lt;P&gt;Hi @johnward4 ,&lt;BR /&gt;
Please try below query,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;![index=businesstrans  customer=*
| stats first(description) as description, sum(quantity) as quantity, first(unit_price) as unit_price by customer, _date, item_id
| stats list(item_id) as item_id, list(description) as Description, list(quantity) as quantity, list(unit_price) as unit_price, sum(eval(unit_price*quantity)) as Transaction_Total by customer, _date 
| table _date, customer, item_id, Description, quantity, unit_price, Transaction_Total
| sort - Transaction_Total][1]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 05:26:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394906#M114707</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2018-09-28T05:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use the stats command on a field value that has duplicate entries?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394907#M114708</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/93915"&gt;@VatsalJagani&lt;/a&gt; ! This query works for everything except it doesn't like the stats sum(unit_price*quantity) as Transaction_Total by _date, customer&lt;/P&gt;

&lt;P&gt;I tried to run an eval under the stats &lt;/P&gt;

&lt;P&gt;eval Transaction_Total = unit_price * quantity   &lt;/P&gt;

&lt;P&gt;and that gives me the calculation total of say for example   quantity was 3 items it multiply by the unit price for a single item and returns the sum in Transaction_Total but it is showing line by line and I need to group everything as a single transaction with the transaction_total showing the sum of all of their purchases&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:24:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394907#M114708</guid>
      <dc:creator>johnward4</dc:creator>
      <dc:date>2020-09-29T21:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use the stats command on a field value that has duplicate entries?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394908#M114709</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/62657"&gt;@johnward4&lt;/a&gt;,&lt;/P&gt;

&lt;P&gt;It is &lt;BR /&gt;
    stats sum(eval(unit_price*quantity))   and Not stats sum(unit_price*quantity), change and see should work fine.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:24:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394908#M114709</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2020-09-29T21:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use the stats command on a field value that has duplicate entries?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394909#M114710</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/80230"&gt;@Vijeta&lt;/a&gt; and &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/93915"&gt;@VatsalJagani&lt;/a&gt; !! I didn't even know that you could run an eval in a stats command like, that will be def useful to me.  Last question if you don't mind..&lt;/P&gt;

&lt;P&gt;I'm using the query as a drilldown from my main bar graph panel displaying total purchases by customer and passing in the value.name2 (selectCustomer) to this drilldown panel.  My overall goal would be able to group the transactions by customer, _date AND most important broken out by  rtl_loc_id aka store&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=sales cust_party_id=$selectCustomer$
| stats first(rtl_loc_id) as rtl_loc_id, first(description) as description, sum(quantity) as quantity, first(unit_price) as unit_price by cust_party_id, business_date, item_id
| eval unit_price = round(unit_price, 2)
 | stats list(rtl_loc_id) as Store_ID, list(item_id) as item_id, list(description) as Description, list(quantity) as quantity, list(unit_price) as unit_price, sum(eval(unit_price*quantity)) as Transaction_Total by cust_party_id, business_date 
 | table _date, cust_party_id, Store_ID, item_id, Description, quantity, unit_price, Transaction_Total
 | sort - quantity
| rename unit_price as Sales_Price
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:24:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394909#M114710</guid>
      <dc:creator>johnward4</dc:creator>
      <dc:date>2020-09-29T21:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use the stats command on a field value that has duplicate entries?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394910#M114711</link>
      <description>&lt;P&gt;From what I understand is you want the transactions broken by customer_id, Date and Store. You can use rtl_loc_id in your by clause instead of list. &lt;/P&gt;

&lt;P&gt;| stats  list(item_id) as item_id, list(description) as Description, list(quantity) as quantity, list(unit_price) as unit_price, sum(eval(unit_price*quantity)) as Transaction_Total by cust_party_id, rtl_loc_id ,business_date  | rename rtl_loc_id are Store_ID , unit_price as Sales_Price | sort - quantity&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:24:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-the-stats-command-on-a-field-value-that-has/m-p/394910#M114711</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2020-09-29T21:24:44Z</dc:date>
    </item>
  </channel>
</rss>

