Splunk Search

How to perform chart command with two multifield columns in the table?

Ashwini_5
Explorer

I performing the chart command for the below kind of table. 

 

Command : [|Chart  values(course) as course  over ID by status]

 

Ashwini_5_0-1671099564575.png

 

Received Output as BELOW: 

 

Ashwini_5_1-1671099713528.png

 

Expected Output : 

Ashwini_5_2-1671099792212.png

Kindly help to resolve this . I have tried |MVExpand  status also . . But it is picking only the first value and providing wrong output .  

 

Labels (1)
Tags (2)
0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

@Ashwini_5 - Here is fully dynamic query that works with N number of course and status values:

| eval combined=mvzip(course, status, "|")
| mvexpand combined
| eval course=mvindex(split(combined, "|"), 0), status=mvindex(split(combined, "|"), 1)
| chart values(status) as status over ID by course

VatsalJagani_0-1671201928367.png

 

I hope this helps!!!

0 Karma

FelixLeh
Contributor

Hey @Ashwini_5 !

I'm Assuming that both Course and status are multivalve fields.
If my assumption is true the following search should hopefully be able to aid you in finding the solution.

| makeresults 
| fields - _time
| eval ID = 1, course = "Course A,Course B,Course C",status="Expired OK Expired"
| append
    [| makeresults 
| fields - _time
| eval ID = 2, course = "Course A,Course B,Course C",status="OK OK Expired"]
| append
    [| makeresults 
| fields - _time
| eval ID = 3, course = "Course A,Course B,Course C",status="OK OK OK"]
| fields ID course status
| makemv course delim=","
| makemv status delim=" "
| mvexpand course
| eval status=case(course="Course A",mvindex(status,0,0),course="Course B",mvindex(status,1,1),course="Course C",mvindex(status,2,2))
| chart values(status) as status over ID by course
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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...