<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Multiple If Statements (Comparing Two Columns) in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Multiple-If-Statements-Comparing-Two-Columns/m-p/397624#M115404</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have information being indexed from a website that does constant ping tests. The information that I am retrieving is the name of the website, the date and time, and status (which is either up, down, unconfirmed_down). I was able to write a command to pull this information and sort by status so that I know how many responses per status. The problem with my code is that if either of the status fields up, down, unconfirmed_down don't have any information in it, my final results end up turning blank. I know this is occurring because when I try to create the total time of the status and any of those blanks then total is empty or null, which doesn't allow me to get the percentage. I have been trying to figure out the best way to calculate the total field. I have been trying to use case and if statements so that if any of those fields are empty then it will only add the other fields together... I know that might be a little confusing but here is the code.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=pingdom Name="appointments.jennycraig.com/set-appointment" | timechart count(status) span=1mon by status | table _time, down, up, unconfirmed_down, total  | eval total = case(isnull(down+up+unconfirmed_down),up,up=if(isnull(unconfirmed_down),up+down,up+unconfirmed_down),1=1,up+down+unconfirmed_down) | eval down=down/total*100, down=round(down,3),up=if(isnull(unconfirmed_down),up,(up+unconfirmed_down))/total*100, up=round(up,3)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is one of the variations. I have tried to use if statements within case, but I don' t think that is possible. Does anyone have a better solution to this?&lt;/P&gt;

&lt;P&gt;Thanks in advance for your assistance in this. I have been putting many hours of thought into this before finally throwing in the towel for help.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 22:42:00 GMT</pubDate>
    <dc:creator>dfrench151</dc:creator>
    <dc:date>2020-09-29T22:42:00Z</dc:date>
    <item>
      <title>Multiple If Statements (Comparing Two Columns)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Multiple-If-Statements-Comparing-Two-Columns/m-p/397624#M115404</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have information being indexed from a website that does constant ping tests. The information that I am retrieving is the name of the website, the date and time, and status (which is either up, down, unconfirmed_down). I was able to write a command to pull this information and sort by status so that I know how many responses per status. The problem with my code is that if either of the status fields up, down, unconfirmed_down don't have any information in it, my final results end up turning blank. I know this is occurring because when I try to create the total time of the status and any of those blanks then total is empty or null, which doesn't allow me to get the percentage. I have been trying to figure out the best way to calculate the total field. I have been trying to use case and if statements so that if any of those fields are empty then it will only add the other fields together... I know that might be a little confusing but here is the code.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=pingdom Name="appointments.jennycraig.com/set-appointment" | timechart count(status) span=1mon by status | table _time, down, up, unconfirmed_down, total  | eval total = case(isnull(down+up+unconfirmed_down),up,up=if(isnull(unconfirmed_down),up+down,up+unconfirmed_down),1=1,up+down+unconfirmed_down) | eval down=down/total*100, down=round(down,3),up=if(isnull(unconfirmed_down),up,(up+unconfirmed_down))/total*100, up=round(up,3)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is one of the variations. I have tried to use if statements within case, but I don' t think that is possible. Does anyone have a better solution to this?&lt;/P&gt;

&lt;P&gt;Thanks in advance for your assistance in this. I have been putting many hours of thought into this before finally throwing in the towel for help.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:42:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Multiple-If-Statements-Comparing-Two-Columns/m-p/397624#M115404</guid>
      <dc:creator>dfrench151</dc:creator>
      <dc:date>2020-09-29T22:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple If Statements (Comparing Two Columns)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Multiple-If-Statements-Comparing-Two-Columns/m-p/397625#M115405</link>
      <description>&lt;P&gt;I should also note, I have attempted to nest multiple if statements within an if statement, but I don't think I can do this either, that or I am not correctly writing it out... It would be preferable to have an if statement use the other field if one field has nothing into it, but I don't think you can create variables that update depending on the results&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jan 2019 13:49:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Multiple-If-Statements-Comparing-Two-Columns/m-p/397625#M115405</guid>
      <dc:creator>dfrench151</dc:creator>
      <dc:date>2019-01-12T13:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple If Statements (Comparing Two Columns)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Multiple-If-Statements-Comparing-Two-Columns/m-p/397626#M115406</link>
      <description>&lt;P&gt;@dfrench151,&lt;/P&gt;

&lt;P&gt;As you mentioned if you are getting the total as empty because one of the fields is null, then fill the null with 0 before calculation or use addtotals. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|fillnull value=0 down, up, unconfirmed_down
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If this is not what you are looking for, then sample data and required output will be helpful.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jan 2019 15:20:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Multiple-If-Statements-Comparing-Two-Columns/m-p/397626#M115406</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-01-12T15:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple If Statements (Comparing Two Columns)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Multiple-If-Statements-Comparing-Two-Columns/m-p/397627#M115407</link>
      <description>&lt;P&gt;I have actually figured it out. Instead of trying to have my formula count based on if fields are null for the totals I found that I can just use the addtotals command to get the total number that I need so I can get my percentage. I am still curious though if it is possible to have an If statement within an if statement (i.e. If(x, then Y, else If(x, then, Y, else If(x, then y, then z)))&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jan 2019 15:26:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Multiple-If-Statements-Comparing-Two-Columns/m-p/397627#M115407</guid>
      <dc:creator>dfrench151</dc:creator>
      <dc:date>2019-01-12T15:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple If Statements (Comparing Two Columns)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Multiple-If-Statements-Comparing-Two-Columns/m-p/397628#M115408</link>
      <description>&lt;P&gt;Yes it's possible, try below example. YOu may change values of a,b,c and see the difference&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults|eval a=10,b=5,c=1|eval x=if(a==10,if(b==5,if(c==1,"True","C FALSE"),"B FALSE"),"A FALSE")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Jan 2019 15:36:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Multiple-If-Statements-Comparing-Two-Columns/m-p/397628#M115408</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-01-12T15:36:00Z</dc:date>
    </item>
  </channel>
</rss>

