Splunk Search

How edit my search so that appendcols command appends results correctly?

cchange
Path Finder

Hi,

I'm trying to append the results from two tables. I used appendcols with override option. But results showing different in final output.

I used following query

Search query 1 | appendcols override=true [Search query2]

First Search Results

Team FM    
A         35    
B         81    
C          30    

Second sub Search Results

Team  SM
D       40
E       620
A   180
B        59
C           53

Currently results are showing

Team FM    SM
D   35  40
E   81  620
A   30  180
B   -      59
C   -    53

Results should show in below format. I'm not sure if this is a bug with appendcols option. Any inputs or help is appreciated.

Team FM    SM
D    -  40
E   -   620
A   35   180
B   81  59
C   30   53

thanks

0 Karma
1 Solution

somesoni2
Revered Legend

The appendcols appends the result of two searches, row/result by result (row 1 of search 1 with row 1 of search 2 and so on). The override field defines if same field name is present in both the results, which value to keep (keep from search 1 or overwrite from search 2). I see that results from your both the searches doesn't have same row count and they are not sorted either, making appendcols not the ideal command for your need. What you need is to merge both results and keep values from second search, then you should use combination of append and stats like this.

To keep results from search 1

Search query 1 | append [Search query2] | stats list(FM) as FM list(SM) as SM by Team | eval FM=mvindex(FM,0)  | eval SM=mvindex(SM,0)

To keep results from search 2

Search query 1 | append [Search query2] | stats list(FM) as FM list(SM) as SM by Team | eval FM=mvindex(FM,-1)  | eval SM=mvindex(SM,-1)

View solution in original post

0 Karma

somesoni2
Revered Legend

The appendcols appends the result of two searches, row/result by result (row 1 of search 1 with row 1 of search 2 and so on). The override field defines if same field name is present in both the results, which value to keep (keep from search 1 or overwrite from search 2). I see that results from your both the searches doesn't have same row count and they are not sorted either, making appendcols not the ideal command for your need. What you need is to merge both results and keep values from second search, then you should use combination of append and stats like this.

To keep results from search 1

Search query 1 | append [Search query2] | stats list(FM) as FM list(SM) as SM by Team | eval FM=mvindex(FM,0)  | eval SM=mvindex(SM,0)

To keep results from search 2

Search query 1 | append [Search query2] | stats list(FM) as FM list(SM) as SM by Team | eval FM=mvindex(FM,-1)  | eval SM=mvindex(SM,-1)
0 Karma

cchange
Path Finder

Thanks. It worked.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...