Dashboards & Visualizations

How to compare the count of two fields from different source types ?

Ombessam
Path Finder

How can I get the following visualization ?

Field1VsField2.png

I've tried the following commands:

(index="my_index" sourcetype="sourcetype1") OR (index="my_index" sourcetype="sourcetype2")
| fields field1 field2
| stats count(field1) as Field1, count(field2) as Field2

and I getting the following graph

Screenshot 2025-04-01 at 19.00.30.png

Labels (1)
0 Karma
1 Solution

livehybrid
SplunkTrust
SplunkTrust

Hi @Ombessam ,

To get the desired visualisation comparing the counts of field1 and field2, you need to transform the results of your stats command so that the field names become values in one column and the counts become values in another. The transpose command is suitable for this.

(index="my_index" sourcetype="sourcetype1") OR (index="my_index" sourcetype="sourcetype2")
| stats count(field1) as Field1, count(field2) as Field2
| transpose
| rename column as FieldName, "row 1" as Count

 

This structure (FieldName, Count) allows you to configure your bar chart visualization.

livehybrid_0-1743537129332.png

 

You could also achieve this with:

(index="my_index" sourcetype="sourcetype1") OR (index="my_index" sourcetype="sourcetype2")
| eval x="x" 
| stats count(status) as field1, count(bytes) as field2 by x

livehybrid_1-1743537175169.png

 

🌟 Did this answer help you? If so, please consider:

  • Adding kudos to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing

View solution in original post

Ombessam
Path Finder

Awesome @livehybrid , Thanks

0 Karma

livehybrid
SplunkTrust
SplunkTrust

Hi @Ombessam ,

To get the desired visualisation comparing the counts of field1 and field2, you need to transform the results of your stats command so that the field names become values in one column and the counts become values in another. The transpose command is suitable for this.

(index="my_index" sourcetype="sourcetype1") OR (index="my_index" sourcetype="sourcetype2")
| stats count(field1) as Field1, count(field2) as Field2
| transpose
| rename column as FieldName, "row 1" as Count

 

This structure (FieldName, Count) allows you to configure your bar chart visualization.

livehybrid_0-1743537129332.png

 

You could also achieve this with:

(index="my_index" sourcetype="sourcetype1") OR (index="my_index" sourcetype="sourcetype2")
| eval x="x" 
| stats count(status) as field1, count(bytes) as field2 by x

livehybrid_1-1743537175169.png

 

🌟 Did this answer help you? If so, please consider:

  • Adding kudos to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...