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
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: Matching cron expressions

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

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...