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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...