@maniishpawar, can you please add some sample data where Only the first match count is returned ?
| makeresults
| eval _raw="some conflict while finding FOREIGN_KEY"
| append
[| makeresults
| eval _raw="Event with nonexistingvalue"]
| eval P_ErrMsg=case(searchmatch("conflict"), "FKEY1"
,searchmatch("FOREIGN KEY"), "FKEY"
,searchmatch("nonexistingvalue"),"garbagevalue")
| stats count by P_ErrMsg
As @DalJeanis has mentioned you should avoid a command like | eval _rawtext=_raw to copy raw data over from one field to another. Alternative to Dal's approach, you can also try searchmatch() function which matches your criteria against the _raw data. Splunk Documentation for reference: http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ConditionalFunctions#searchmatch.28X.29
PS: Pipes with | makeresults and | append are used to generate some mock data. You would need to replace with your base search. Also it is better id you added your own mocked up sample events ( with sensitive information masked or anonymized )
| makeresults
| eval _raw="some conflict while finding FOREIGN_KEY"
| append
[| makeresults
| eval _raw="Event with nonexistingvalue"]
... View more