How do I calculate multiple percentages based off a key?
I've got a log string that says "finished their work" or "failed their work." and a parseable subfield containing the person's name.
I trying to calculate the success percentage given a name (i.e. if "Joe finished their work" 9 times but failed 1 time, and Jim finished 7 but failed 3 times, I need a view that shows "Joe: 90%", "Jim: 70%")
Here's what I have tried:
("finished their work" or "failed their work")
| parse regex "(?<status>finished|failed) their work"
| json field=_raw "arg0.details.person.name" as name
| concat(name, "-", status) as nameAndStatus
| count as taskTotal by task
| count as numerator by nameAndStatus
Obviously this doesn't work because of the dual count-condition, but I'd like to then do numerator divided by taskTotal for each task to view the output.
-
Hi Wofi,
Can you give the following a try?
("finished their work" or "failed their work")
| parse regex "(?<status>finished|failed) their work"
| json field=_raw "arg0.details.person.name" as name
| if(status="finished", 1, 0) as finished
| if(status="failed", 1, 0) as failed
| sum(finished) as finished, sum(failed) as failed, count as total by name
| (finished/total)*100 as pct_finished
What this does is puts a 1 or 0 into a "finished" or "failed" column. We can then use those to sum up the number of finished v. failed per user and then it's just the simple math against the total count per user to get the percentage.
I hope this will help with getting the values your looking for.
Please sign in to leave a comment.
Comments
3 comments