title: Why is Logic Apps' if() expression executing both code paths simultaneously?
body: <p>I am getting failures on a Logic App because the if() expression is executing both the true and false paths. The false path is going to fail if it executes which is why I put it in an if() in the first place.</p>
  
  <p>The expression is:</p>
  
  <pre><code>if(empty(triggerBody()?['data']?['eta']), null, formatDateTime(triggerBody()?['data']?['eta'], 'yyyy-MM-dd'))
  </code></pre>
  
  <p>I've also tried:</p>
  
  <pre><code>if(equals(triggerBody()?['data']?['eta'], null), null, formatDateTime(triggerBody()?['data']?['eta'], 'yyyy-MM-dd'))
  </code></pre>
  
  <p>The data is null:</p>
  
  <pre><code>...
  "data": {
      "eta": null,
  ...
  </code></pre>
  
  <p>I've tested this by swapping out formatDateTime() with a string like 'is not null'. When I do this I get the expected output (null) and no failure.</p>
  
  <p><strong>Update:</strong> Someone from the Logic Apps team suggested the following as an alternative:</p>
  
  <pre><code>@if(empty(triggerBody()?['data']?['eta']), null, formatDateTime(coalesce(triggerBody()?['data']?['eta'], '1999-01-01'), 'yyyy-MM-dd'))
  </code></pre>
  
  <p>The usage of <code>coalesce()</code> is suggested here because it returns the first non-null result. So in this way I can at least be assured of providing a value to <code>formatDateTime()</code>.</p>