Dashboards & Visualizations

Unable to create new field with Case Statement

POR160893
Builder

Hi,

 

I am using a Case statement to create a new field whose values depend on certain other fields taking other value.

So, the new field I am creating is called "XYZ".
For events whose field "Planned Migration Completion Iteration" has a value beginning with "Decom by", then the "XYZ" field would have a value of "Done".
Similarly,  for events whose field "Migration Comments" has a value equal to "In progress", then the "XYZ" field would have a value of "In progress".
Finally, for all other scenarios, the XYZ takes the value of "Not Started".

However, this is what my current Case statement looks like, where it ONLY outputs the "Not Started" case:

POR160893_0-1654120006076.png

 


Can you please help?

Many thanks 🙂

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

@POR160893 - Use single quotes for field names with spaces. Also * does not work with if eval statement, so use the like() function instead.

 

| eval xyz=case('Planned Migration Completion Iteration'==like("Decom by%"), "Done", 'Planned Migration Completion Iteration'=="In progress", "In progress", 1==1, "Not Started")

 

 

I hope this helps!!!

0 Karma

POR160893
Builder

POR160893_0-1654157285418.png

 

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

@POR160893 - Try:

| eval xyz=case(like('Planned Migration Completion Iteration', "Decom by%"), "Done", 'Planned Migration Completion Iteration'=="In progress", "In progress", 1==1, "Not Started")

 

I hope this helps!!!

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @POR160893,

you should try this approach to adapt to your real case:

index=your_index
| eval xyz="Not Started"
| eval xyz=case("Planned Migration Completion Iteration"=like("Decom by%"),"Done", "Planned Migration Completion Iteration"="In progress","In progress")
| table xyz

otherwise, you could try something like this:

index=your_index
| eval xyz=if("Planned Migration Completion Iteration"=like("Decom by%"),"Done", if("Planned Migration Completion Iteration"="In progress","In progress","Not Started"))
| table xyz

One hint, don't use field names with spaces, eventually rename them as last row but use field names without spaces.

Ciao.

Giuseppe

0 Karma

POR160893
Builder

POR160893_0-1654157131982.png



and 

POR160893_1-1654157226063.png

 

0 Karma
Get Updates on the Splunk Community!

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to Officially Supported Splunk ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI! Discover how Splunk’s agentic AI ...