Splunk Search

How to split count by product by another value?

maxmukimov
Explorer

Hi,  I have the following query: 

 

| bin _time span=1d | stats count as ProductCount by applysourcetype, product, _time   

| where _time=relative_time(now(), "-d@d") or _time=relative_time(now(), "-8d@d")   

| eval when = if(_time=relative_time(now(), "-d@d"), "(Yesterday)", "(7 Days Ago)")  

| eval "Products Ordered {when}" = ProductCount    

| fields - _time ProductCount  when

| stats  values(*) as * by product , applysourcetype

 

 

and I'm getting following output: banana.PNG

How can make product filed one row for unique product? 

Labels (3)
0 Karma

s2_splunk
Splunk Employee
Splunk Employee
| mvexpand product

at the end of your search should do the trick. mvexpand docs here.

0 Karma

maxmukimov
Explorer

Getting the same results when I added

| mvexpand product
Tags (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| stats list(*) as * by product
0 Karma

maxmukimov
Explorer

got this 

banana1.PNG

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

One unique product per row - which is what you said. If this is not what you wanted, perhaps you can give an example of what you were expecting?

0 Karma

maxmukimov
Explorer

From original query I’m getting something like this :

1.PNG

I want to get something like this:

 

2.PNG

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

The standard table view doesn't merge cells across rows. Using stats list(*) as * by product should at least group the fields into multi-value lists which is close to what you want.  If you still want separate rows for the counts, with blank entries in the product column for subsequent rows for the same product, you could use some CSS to hide them. This is a little fiddly to do but possible.

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...