title: How do I build a Tableau divide function based on a case statement?
body: <p>In Tableau I have a fully normalized dataset e.g. I have a field for a dimension (country) a field for metric (profit and sales) and a field for value (fact numbers).</p>
  
  <p>I was wondering if I can write a case statement where I divide profit by sales e.g. in SQL it would be something similar to:</p>
  
  <pre><code>(case when metric = 'profit' then [value] else 0 ) / (case when metric = 'sales' then [value])
  </code></pre>
  
  <p>I've tried building the case statement using the Tableau calculated field functionality but it returns zero - I suspect because I'm trying to do this in 1 step whilst in SQL I think it might be a 2 step process.</p>
  
  <p>Please note that the simple solution of re-structuring the data isn't really an option as this creates other issues (not outlined in my simplistic example).</p>