<?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: Tiered pricing data calculation in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Tiered-pricing-data-calculation/m-p/43532#M8131</link>
    <description>&lt;P&gt;Nice that works perfectly. A good example of how multikv works too.&lt;/P&gt;

&lt;P&gt;My only issue now is the using this as a temporal style lookup.&lt;/P&gt;

&lt;P&gt;Turns out it is possible by adding a max_matches=3 to the transforms.conf . Again however as you mentioned if some retailers have less/more tiers than others it breaks the whole system.&lt;/P&gt;</description>
    <pubDate>Fri, 24 May 2013 00:44:37 GMT</pubDate>
    <dc:creator>phoenixdigital</dc:creator>
    <dc:date>2013-05-24T00:44:37Z</dc:date>
    <item>
      <title>Tiered pricing data calculation</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Tiered-pricing-data-calculation/m-p/43530#M8129</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;I have a CSV file with the following information&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;date,retailer,lower,upper,price_rate
20120621,retailer1,0,10,10
20120621,retailer1,10,20,8
20120621,retailer1,20,100,5
20120621,retailer2,0,10,10
20120621,retailer2,10,20,8
20120621,retailer2,20,100,5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now there are Splunk events which contains hourly usage&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time, retailer, usage
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So I want to get a sum of all the usage over one month with something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="myData" | stats sum(usage) by retailer
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I then want to calculate a total cost.&lt;/P&gt;

&lt;P&gt;So for example the if the total usage over the month was 50.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;The first 10 would be priced at $10 per unit&lt;/LI&gt;
&lt;LI&gt;The second 10 units would be priced at $8 per unit&lt;/LI&gt;
&lt;LI&gt;The remaining 30 units would be priced at $5 per unit&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;How can I do this in a Splunk search?&lt;/P&gt;

&lt;P&gt;Harder still the original CSV was actually intended to be a time based lookup so it would only use the associated date section based on the _time from the events.&lt;/P&gt;

&lt;P&gt;I am thinking maybe I should restructure this CSV and join it 3 times in the props.conf somehow???&lt;/P&gt;

&lt;P&gt;Any assistance would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2013 01:32:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Tiered-pricing-data-calculation/m-p/43530#M8129</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2013-05-23T01:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Tiered pricing data calculation</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Tiered-pricing-data-calculation/m-p/43531#M8130</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;im skipping the time based part for now. If you do the lookup after your stats command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="myData" | stats sum(usage) as sum by retailer   | lookup retail retailer
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the lookup will add the tiered pricing information as multivalued fields.&lt;/P&gt;

&lt;P&gt;You can append this eval to get your result ( I don't think, that Splunk has any looping operators that can be aplied to an event/the mv fields of an event):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval price=case (
sum&amp;gt;mvindex(lower,0) AND sum&amp;lt;=tonumber(mvindex(upper,0)),tonumber(mvindex(price_rate,0))*sum,

sum&amp;gt;=tonumber(mvindex(lower,1)) AND sum&amp;lt;=tonumber(mvindex(upper,1)),tonumber(mvindex(price_rate,0))*tonumber(mvindex(upper,0))+(sum-tonumber(mvindex(upper,0)))*tonumber(mvindex(price_rate,1)),


sum&amp;gt;=tonumber(mvindex(lower,2)) AND sum&amp;lt;=tonumber(mvindex(upper,2)),tonumber(mvindex(price_rate,0))*tonumber(mvindex(upper,0))+tonumber(mvindex(price_rate,1))*(tonumber(mvindex(upper,1))-tonumber(mvindex(upper,0)))+(sum-tonumber(mvindex(upper,1)))*tonumber(mvindex(price_rate,2))
)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This obviously only works if you you have only 3 ranges and gets more complex with every additional range you add.&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2013 22:27:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Tiered-pricing-data-calculation/m-p/43531#M8130</guid>
      <dc:creator>chris</dc:creator>
      <dc:date>2013-05-23T22:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: Tiered pricing data calculation</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Tiered-pricing-data-calculation/m-p/43532#M8131</link>
      <description>&lt;P&gt;Nice that works perfectly. A good example of how multikv works too.&lt;/P&gt;

&lt;P&gt;My only issue now is the using this as a temporal style lookup.&lt;/P&gt;

&lt;P&gt;Turns out it is possible by adding a max_matches=3 to the transforms.conf . Again however as you mentioned if some retailers have less/more tiers than others it breaks the whole system.&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2013 00:44:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Tiered-pricing-data-calculation/m-p/43532#M8131</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2013-05-24T00:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: Tiered pricing data calculation</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Tiered-pricing-data-calculation/m-p/43533#M8132</link>
      <description>&lt;P&gt;I'm thinking the best solution is to  just change the CSV format to.&lt;/P&gt;

&lt;P&gt;date,retailer,upper_tier1,price_tier1,,upper_tier2,price_tier2,upper_tier3,price_tier3&lt;/P&gt;

&lt;P&gt;Then use a similar method as you suggested. That will allow me to use temporal lookups without worrying about changes in the number of tiers. If they add additional tiers I will just have to change my searches.&lt;/P&gt;

&lt;P&gt;Thanks again for the assist.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:58:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Tiered-pricing-data-calculation/m-p/43533#M8132</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2020-09-28T13:58:17Z</dc:date>
    </item>
  </channel>
</rss>

