<?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 How to Merge Rows in Table With Similar Data, While Maintaining Records That Do Not Match in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-Merge-Rows-in-Table-With-Similar-Data-While-Maintaining/m-p/589170#M205179</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;We are currently working with two sets of data that have similar fields. We would like to align matching events in one row (payment amount, category/source and account number) while also maintaining the values that do not match for failed processing.&amp;nbsp; Below are some screenshots of what the data looks like now in four rows, as well as what we're hoping to visualize in 3 rows. Any assistance would be greatly appreciated!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Razziq_0-1647363812406.png" style="width: 725px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/18525i521B0FDC15F991E5/image-dimensions/725x154?v=v2" width="725" height="154" role="button" title="Razziq_0-1647363812406.png" alt="Razziq_0-1647363812406.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Razziq_1-1647363829846.png" style="width: 725px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/18526iF8F8347B8975CEEA/image-dimensions/725x154?v=v2" width="725" height="154" role="button" title="Razziq_1-1647363829846.png" alt="Razziq_1-1647363829846.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Below is our current search:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index="index1" Tag="Tag1"
| stats values(PaymentAmount) as PaymentAmount by PaymentChannel,AccountId,PaymentCategory,ResponseStatus,StartDT
| rename AccountId as AccountNumber
| rename PaymentChannel as A_PaymentChannel
| rename PaymentCategory as A_PaymentCategory
| rename ResponseStatus as A_ResponseStatus
| rename StartDT as A_Time
| append
[search index="index2" sourcetype="source2"
| rename PaymentAmount as M_PayAmt
| eval PayAmt = tonumber(round(M_PayAmt,2))
| rex field=source "M_(?&amp;lt;M_Source&amp;gt;\w+)_data.csv"
| rename "TERMINAL ID" as M_KioskID
| rename "ResponseStatus" as "M_ResponseStatus"
| rename "KIOSK REPORT TIME" as M_Time
| eval _time =strptime(M_Time,"%Y-%m-%d %H:%M:%S.%3Q")
| addinfo
| where _time&amp;gt;=info_min_time AND (_time&amp;lt;=info_max_time OR info_max_time="+Infinity")
| stats values(PayAmt) as M_PayAmt latest(M_Time) by AccountNumber, M_Source, M_ResponseStatus,M_KioskID
| rename latest(M_Time) as M_Time
| table M_PayAmt,AccountNumber, M_Source, M_KioskID,M_ResponseStatus,M_Time
| mvexpand M_PayAmt]
| eval A_PaymentTotal = "$" + PaymentAmount
| eval M_PayAmt = "$" + M_PayAmt
| eval joiner = AccountNumber
| table AccountNumber,A_PaymentChannel,M_KioskID,A_PaymentCategory,M_Source,A_PaymentTotal,M_PayAmt,A_ResponseStatus,M_ResponseStatus,A_Time,_Time
| eval M_PayAmt=if(isnull(M_PayAmt),"Unknown",M_PayAmt)
| eval A_PaymentTotal=if(isnull(A_PaymentTotal),"Unknown",A_PaymentTotal)
| eval A_Time=if(isnull(A_Time), M_Time, A_Time)
| eval M_Time=if(isnull(M_Time), A_Time, M_Time)
| sort by M_Time desc

&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 15 Mar 2022 17:55:39 GMT</pubDate>
    <dc:creator>Razziq</dc:creator>
    <dc:date>2022-03-15T17:55:39Z</dc:date>
    <item>
      <title>How to Merge Rows in Table With Similar Data, While Maintaining Records That Do Not Match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Merge-Rows-in-Table-With-Similar-Data-While-Maintaining/m-p/589170#M205179</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;We are currently working with two sets of data that have similar fields. We would like to align matching events in one row (payment amount, category/source and account number) while also maintaining the values that do not match for failed processing.&amp;nbsp; Below are some screenshots of what the data looks like now in four rows, as well as what we're hoping to visualize in 3 rows. Any assistance would be greatly appreciated!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Razziq_0-1647363812406.png" style="width: 725px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/18525i521B0FDC15F991E5/image-dimensions/725x154?v=v2" width="725" height="154" role="button" title="Razziq_0-1647363812406.png" alt="Razziq_0-1647363812406.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Razziq_1-1647363829846.png" style="width: 725px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/18526iF8F8347B8975CEEA/image-dimensions/725x154?v=v2" width="725" height="154" role="button" title="Razziq_1-1647363829846.png" alt="Razziq_1-1647363829846.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Below is our current search:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index="index1" Tag="Tag1"
| stats values(PaymentAmount) as PaymentAmount by PaymentChannel,AccountId,PaymentCategory,ResponseStatus,StartDT
| rename AccountId as AccountNumber
| rename PaymentChannel as A_PaymentChannel
| rename PaymentCategory as A_PaymentCategory
| rename ResponseStatus as A_ResponseStatus
| rename StartDT as A_Time
| append
[search index="index2" sourcetype="source2"
| rename PaymentAmount as M_PayAmt
| eval PayAmt = tonumber(round(M_PayAmt,2))
| rex field=source "M_(?&amp;lt;M_Source&amp;gt;\w+)_data.csv"
| rename "TERMINAL ID" as M_KioskID
| rename "ResponseStatus" as "M_ResponseStatus"
| rename "KIOSK REPORT TIME" as M_Time
| eval _time =strptime(M_Time,"%Y-%m-%d %H:%M:%S.%3Q")
| addinfo
| where _time&amp;gt;=info_min_time AND (_time&amp;lt;=info_max_time OR info_max_time="+Infinity")
| stats values(PayAmt) as M_PayAmt latest(M_Time) by AccountNumber, M_Source, M_ResponseStatus,M_KioskID
| rename latest(M_Time) as M_Time
| table M_PayAmt,AccountNumber, M_Source, M_KioskID,M_ResponseStatus,M_Time
| mvexpand M_PayAmt]
| eval A_PaymentTotal = "$" + PaymentAmount
| eval M_PayAmt = "$" + M_PayAmt
| eval joiner = AccountNumber
| table AccountNumber,A_PaymentChannel,M_KioskID,A_PaymentCategory,M_Source,A_PaymentTotal,M_PayAmt,A_ResponseStatus,M_ResponseStatus,A_Time,_Time
| eval M_PayAmt=if(isnull(M_PayAmt),"Unknown",M_PayAmt)
| eval A_PaymentTotal=if(isnull(A_PaymentTotal),"Unknown",A_PaymentTotal)
| eval A_Time=if(isnull(A_Time), M_Time, A_Time)
| eval M_Time=if(isnull(M_Time), A_Time, M_Time)
| sort by M_Time desc

&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 15 Mar 2022 17:55:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Merge-Rows-in-Table-With-Similar-Data-While-Maintaining/m-p/589170#M205179</guid>
      <dc:creator>Razziq</dc:creator>
      <dc:date>2022-03-15T17:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to Merge Rows in Table With Similar Data, While Maintaining Records That Do Not Match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Merge-Rows-in-Table-With-Similar-Data-While-Maintaining/m-p/589646#M205306</link>
      <description>&lt;P&gt;Let's call the one with index=index1 Tag=Tag1 the "A" search; call the other "M" search. &amp;nbsp;Drawing from your mockups AND sample code, the requirement can be summarized as&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Join the "A" search and "M" search by AccountNumber&lt;/LI&gt;&lt;LI&gt;Show amounts as "UNKNOWN" when value is missing.&lt;/LI&gt;&lt;LI&gt;If "Time" from one search is missing, fill with that from the other.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;This can be done with stats. &amp;nbsp;See if the following works:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="index1" Tag="Tag1"
| stats values(PaymentAmount) as A_PaymentTotal by PaymentChannel,AccountId,PaymentCategory,ResponseStatus,StartDT ``` subsequent code and mockups use "A_PaymentTotal" instead of "PaymentAmount" ```
| rename AccountId as AccountNumber
| rename PaymentChannel as A_PaymentChannel
| rename PaymentCategory as A_PaymentCategory
| rename ResponseStatus as A_ResponseStatus
| rename StartDT as A_Time
| append
[search index="index2" sourcetype="source2"
| rename PaymentAmount as M_PayAmt
| eval PayAmt = tonumber(round(M_PayAmt,2))
| rex field=source "M_(?&amp;lt;M_Source&amp;gt;\w+)_data.csv"
| rename "TERMINAL ID" as M_KioskID
| rename "ResponseStatus" as "M_ResponseStatus"
| rename "KIOSK REPORT TIME" as M_Time
| eval _time =strptime(M_Time,"%Y-%m-%d %H:%M:%S.%3Q")
| addinfo
| where _time&amp;gt;=info_min_time AND (_time&amp;lt;=info_max_time OR info_max_time="+Infinity")
| stats values(PayAmt) as M_PayAmt latest(M_Time) as M_time by AccountNumber, M_Source, M_ResponseStatus,M_KioskID ``` rename in stats is more economic ```
| table M_PayAmt,AccountNumber, M_Source, M_KioskID,M_ResponseStatus,M_Time
| mvexpand M_PayAmt]
| stats values(*) as * by AccountNumber ``` join by AccountNumber ```
| eval M_PayAmt=if(isnull(M_PayAmt),"Unknown", "$" + M_PayAmt) ``` small code economy to combine string concatenation inside conditional ```
| eval A_PaymentTotal=if(isnull(A_PaymentTotal),"Unknown", "$" + A_PaymentTotal) ``` illustrated code uses PaymentAmount but mockups do not use this name ```
| eval A_Time=if(isnull(A_Time), M_Time, A_Time)
| eval M_Time=if(isnull(M_Time), A_Time, M_Time)
| table AccountNumber,A_PaymentChannel,M_KioskID,A_PaymentCategory,M_Source,A_PaymentTotal,M_PayAmt,A_ResponseStatus,M_ResponseStatus,A_Time,M_Time ``` illustrated code used _Time instead of M_time ```
| sort by M_Time desc&lt;/LI-CODE&gt;&lt;P&gt;The above code includes some minor adjustments based on mockups, and a little bit of readability. (See comments.) &amp;nbsp;Other than that, it is really just one added stats by AccountNumber, the same technique already employed in both "A" search and "M" search.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2022 09:07:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Merge-Rows-in-Table-With-Similar-Data-While-Maintaining/m-p/589646#M205306</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-03-18T09:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to Merge Rows in Table With Similar Data, While Maintaining Records That Do Not Match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Merge-Rows-in-Table-With-Similar-Data-While-Maintaining/m-p/589752#M205351</link>
      <description>&lt;P&gt;Sorry I should've said that our current search looks more like this:&lt;BR /&gt;&lt;BR /&gt;index="index1" Tag="Tag1"&lt;BR /&gt;| stats values(PaymentAmount) as A_PaymentAmount by PaymentChannel,AccountId,PaymentCategory,ResponseStatus,StartDT&lt;BR /&gt;| rename AccountId as AccountNumber&lt;BR /&gt;| rename PaymentChannel as A_PaymentChannel&lt;BR /&gt;| rename PaymentCategory as A_PaymentCategory&lt;BR /&gt;| rename ResponseStatus as A_ResponseStatus&lt;BR /&gt;| rename StartDT as A_Time&lt;BR /&gt;| append&lt;BR /&gt;[search index="index2" sourcetype="source2"&lt;BR /&gt;| rename PaymentAmount as M_PayAmt&lt;BR /&gt;| eval PayAmt = tonumber(round(M_PayAmt,2))&lt;BR /&gt;| rex field=source "M_(?&amp;lt;M_Source&amp;gt;\w+)_data.csv"&lt;BR /&gt;| rename "TERMINAL ID" as M_KioskID&lt;BR /&gt;| rename "ResponseStatus" as "M_ResponseStatus"&lt;BR /&gt;| rename "KIOSK REPORT TIME" as M_Time&lt;BR /&gt;| eval _time =strptime(M_Time,"%Y-%m-%d %H:%M:%S.%3Q")&lt;BR /&gt;| addinfo&lt;BR /&gt;| where _time&amp;gt;=info_min_time AND (_time&amp;lt;=info_max_time OR info_max_time="+Infinity")&lt;BR /&gt;| stats values(PayAmt) as M_PayAmt by AccountNumber, M_Source, M_KioskID,M_ResponseStatus,M_Time]&lt;BR /&gt;| eval A_PaymentTotal = "$" + A_PaymentAmount&lt;BR /&gt;| eval M_PayAmt = "$" + M_PayAmt&lt;BR /&gt;| eval joiner = AccountNumber&lt;BR /&gt;| stats values(*) as * by joiner&lt;BR /&gt;| table AccountNumber,A_PaymentChannel,Kiosk,A_PaymentCategory,M_Source,A_PaymentTotal,M_PayAmt,A_ResponseStatus,M_ResponseStatus,A_Time,M_Time&lt;BR /&gt;| eval M_PayAmt=if(isnull(M_PayAmt),"Unknown",M_PayAmt)&lt;BR /&gt;| eval A_PaymentTotal=if(isnull(A_PaymentTotal),"Unknown",A_PaymentTotal)&lt;BR /&gt;| eval A_Time=if(isnull(A_Time), M_Time, A_Time)&lt;BR /&gt;| eval M_Time=if(isnull(M_Time), A_Time, M_Time)&lt;BR /&gt;| sort by M_Time desc&lt;BR /&gt;| fields - joiner&lt;BR /&gt;&lt;BR /&gt;However when there are multiple entries for the same account, it lumps them together like so:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Razziq_0-1647633767732.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/18598i4D508CC49CE39C55/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Razziq_0-1647633767732.png" alt="Razziq_0-1647633767732.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;where we are trying to get each to display in their own rows. I was playing with streamstats and pulling in for more info, but there are a lot of variables for differing or missing values between both systems. Once is coming via DBX and the other is coming in from a custom Python data scrape, so _time is not possible to use. It might just be that I'll have to do a lot of streamstats and evals for all situations&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2022 20:04:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Merge-Rows-in-Table-With-Similar-Data-While-Maintaining/m-p/589752#M205351</guid>
      <dc:creator>Razziq</dc:creator>
      <dc:date>2022-03-18T20:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to Merge Rows in Table With Similar Data, While Maintaining Records That Do Not Match</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Merge-Rows-in-Table-With-Similar-Data-While-Maintaining/m-p/589768#M205356</link>
      <description>&lt;P&gt;I was wondering about the cleanness of the mockup and the use of values(PayAmt), etc. &amp;nbsp;If there are multiple transaction from the same account but no transaction ID &lt;EM&gt;AND&lt;/EM&gt; _time is not a reliable determinant, life can be really tough. (My explanation of the cleanness to myself was that maybe you were working with one of those medical labs that used a unique account for every transaction.) &amp;nbsp;In essence, the challenge is semantic because there is no clear definition of a "match". &amp;nbsp;I am not sure how much streamstats can help until defined "match" criteria emerge.&lt;/P&gt;&lt;P&gt;Anyway, if there is anyway to define a unique "primary key" with a group of variables, you can use them in groupby. &amp;nbsp;For example, suppose status "Success" in "A" search matches that of "True" in "M" search, "A" Category matches "M" Source, and the payment amount can be used for matching. &amp;nbsp;Instead of naming these matching fields differently, they should have identical names and matching values should be equal so groupby can do its magic, like&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="index1" Tag="Tag1"
| rename AccountId as AccountNumber
| rename PaymentChannel as A_PaymentChannel
| eval PaymentAmount = round(PaymentAmount, 2)
| rename StartDT as Time
| table PaymentAmount A_PaymentChannel,AccountNumber,PaymentCategory,ResponseStatus, Time, index
| append
[search index="index2" sourcetype="source2"
| eval PaymentAmount = round(PaymentAmount,2)
| rex field=source "M_(?&amp;lt;M_Source&amp;gt;\w+)_data.csv"
    | eval PaymentCategory = if(M_Source == "card", "Credit", "Cash")
    | eval ResponseStatus = if(ResponseStatus == "True", "Success", "Failure")
| rename "TERMINAL ID" as M_KioskID
| rename "KIOSK REPORT TIME" as Time
| eval _time =strptime(Time,"%Y-%m-%d %H:%M:%S.%3Q")
| addinfo
| where _time&amp;gt;=info_min_time AND (_time&amp;lt;=info_max_time OR info_max_time="+Infinity")
| table PaymentAmount AccountNumber, PaymentCategory, M_KioskID,ResponseStatus, Time, index]

| stats values(*) as * by AccountNumber PaymentCategory ResponseStatus
| table AccountNumber,A_PaymentChannel,M_KioskID,PaymentCategory,PaymentAmount,ResponseStatus,Time
| eval PaymentAmount = case(mvcount(index)==2, "$", index=="index1", "A$", index=="index2", "M$") + PaymentAmount
| sort - Time&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 19 Mar 2022 07:46:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Merge-Rows-in-Table-With-Similar-Data-While-Maintaining/m-p/589768#M205356</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-03-19T07:46:40Z</dc:date>
    </item>
  </channel>
</rss>

