<?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 get aggregate information from lookup table and return to outer dbxquery? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600886#M209162</link>
    <description>&lt;P&gt;Thanks a lot! Below is my solution, but there are some minor differences of the total. not sure which part might be wrong.&lt;BR /&gt;&lt;BR /&gt;| dbxquery connection=my_connection query="SELECT * FROM my_table"&lt;BR /&gt;| join max=0&lt;BR /&gt;[| inputlookup lookup.csv | fields *]&lt;BR /&gt;| where date &amp;gt;= start_date and date &amp;lt;= end_date&lt;BR /&gt;| stats sum(amount) as total by id, start_date, end_date&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jun 2022 14:24:58 GMT</pubDate>
    <dc:creator>grantmeng</dc:creator>
    <dc:date>2022-06-07T14:24:58Z</dc:date>
    <item>
      <title>How to get aggregate information from lookup table and return to outer dbxquery?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600752#M209107</link>
      <description>&lt;P&gt;Hi, I have a table as the main search using dbxquery below:&lt;BR /&gt;&lt;BR /&gt;| dbxquery connection=my_connection query="SELECT id, start_date, end_date FROM my_table"&lt;BR /&gt;&lt;BR /&gt;Sample records:&lt;BR /&gt;id, start_date, end_date&lt;BR /&gt;1, 2020-01-01, 2020-01-04&lt;BR /&gt;2, 2020-01-03, 2020-01-05&lt;BR /&gt;......&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;And I have another lookup csv with only two columns below:&lt;BR /&gt;&lt;BR /&gt;date, amount&lt;BR /&gt;2020-01-01, 10&lt;BR /&gt;2020-01-02, 20&lt;BR /&gt;2020-01-03, 10&lt;BR /&gt;2020-01-04, 10&lt;BR /&gt;2020-01-05, 20&lt;BR /&gt;......&lt;BR /&gt;&lt;BR /&gt;The output I want is:&lt;BR /&gt;&lt;BR /&gt;id, start_date, end_date, total&lt;BR /&gt;1, 2020-01-01, 2020-01-04, 50 # total sum of 2020-01-01 to 2020-01-04 (10+20+10+10)&lt;BR /&gt;2, 2020-01-03, 2020-01-05, 40&amp;nbsp;# total sum of 2020-01-03 to 2020-01-05 (10+10+20)&lt;BR /&gt;&lt;BR /&gt;What could be the best way to get this done? Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 19:47:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600752#M209107</guid>
      <dc:creator>grantmeng</dc:creator>
      <dc:date>2022-06-06T19:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get aggregate information from lookup table and return to outer dbxquery?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600778#M209117</link>
      <description>&lt;LI-CODE lang="markup"&gt;| dbxquery connection=my_connection query="SELECT id, start_date, end_date FROM my_table"
| eval row=mvrange(0,2)
| mvexpand row
| eval date=if(row=0, start_date, end_date)
| append
    [| inputlookup lookup.csv]
| sort 0 date
| streamstats sum(amount) as running
| eventstats max(amount) as amount max(running) as running by date
| eventstats range(running) as increase by id
| where row=0
| eval total=amount+increase
| table id start_date end_date total&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 07 Jun 2022 05:05:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600778#M209117</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-06-07T05:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to get aggregate information from lookup table and return to outer dbxquery?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600886#M209162</link>
      <description>&lt;P&gt;Thanks a lot! Below is my solution, but there are some minor differences of the total. not sure which part might be wrong.&lt;BR /&gt;&lt;BR /&gt;| dbxquery connection=my_connection query="SELECT * FROM my_table"&lt;BR /&gt;| join max=0&lt;BR /&gt;[| inputlookup lookup.csv | fields *]&lt;BR /&gt;| where date &amp;gt;= start_date and date &amp;lt;= end_date&lt;BR /&gt;| stats sum(amount) as total by id, start_date, end_date&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 14:24:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600886#M209162</guid>
      <dc:creator>grantmeng</dc:creator>
      <dc:date>2022-06-07T14:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to get aggregate information from lookup table and return to outer dbxquery?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600892#M209165</link>
      <description>&lt;P&gt;What field is your join joining on? In your original question, you did not have any common fields between the fields returned by the dbxquery and the lookup file.&lt;/P&gt;&lt;P&gt;Assuming you have got a common field, the join will join one event from the lookup file so you would be missing any data from the lookup file which did not have a corresponding value in the dbxquery.&lt;/P&gt;&lt;P&gt;Unless I am missing something, I don't see how your query satisfies your requirement.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 15:10:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600892#M209165</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-06-07T15:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to get aggregate information from lookup table and return to outer dbxquery?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600899#M209167</link>
      <description>&lt;P&gt;There is no common field between these two queries. The first one (dbxquery) has start_date/end_date, which are used to check the date range only in the second query (lookup.csv) with its date field.&lt;BR /&gt;&lt;BR /&gt;My solution is try to get the cartesian product first (max=0 for this purpose), for each row in the first query, it should return something below:&lt;/P&gt;&lt;P&gt;id, start_date, end_date,&amp;nbsp; date, amount&lt;BR /&gt;&lt;SPAN&gt;1, 2020-01-01, 2020-01-04,&amp;nbsp;2020-01-01, 10&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;1, 2020-01-01, 2020-01-04,&amp;nbsp;2020-01-02, 20&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;1, 2020-01-01, 2020-01-04,&amp;nbsp;2020-01-03, 10&lt;BR /&gt;1, 2020-01-01, 2020-01-04,&amp;nbsp;2020-01-04, 10&lt;BR /&gt;1, 2020-01-01, 2020-01-04,&amp;nbsp;2020-01-05, 20&lt;BR /&gt;......&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;Then use the date comparison check: date &amp;gt;= start_date AND date &amp;lt;= stop_date to filter out those unmatched rows in the lookup.csv, after that we get below for the first row in the first query:&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1, 2020-01-01, 2020-01-04,&amp;nbsp;2020-01-01, 10&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;1, 2020-01-01, 2020-01-04,&amp;nbsp;2020-01-02, 20&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;1, 2020-01-01, 2020-01-04,&amp;nbsp;2020-01-03, 10&lt;BR /&gt;1, 2020-01-01, 2020-01-04,&amp;nbsp;2020-01-04, 10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Aggregate the above rows by sum, we get:&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1, 2020-01-01, 2020-01-04, 50&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Do you see anything not right? Thanks again!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 15:40:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600899#M209167</guid>
      <dc:creator>grantmeng</dc:creator>
      <dc:date>2022-06-07T15:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get aggregate information from lookup table and return to outer dbxquery?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600908#M209168</link>
      <description>&lt;P&gt;As I said before, join needs a common field between the two data sources, you don't appear to have one, or at least, not the way you have described your data and your search.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 16:08:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600908#M209168</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-06-07T16:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get aggregate information from lookup table and return to outer dbxquery?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600913#M209169</link>
      <description>&lt;P&gt;I searched and saw someone mentioned Splunk could do cartesian product in this way. I'll do more research, thanks for your solution again.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 16:40:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-aggregate-information-from-lookup-table-and-return-to/m-p/600913#M209169</guid>
      <dc:creator>grantmeng</dc:creator>
      <dc:date>2022-06-07T16:40:42Z</dc:date>
    </item>
  </channel>
</rss>

