title: Netsuite Case When Saved Search Formula including division
body: <p>I am fairly new to NetSuite, and looking to move a report nomally ran in excel</p>
  
  <p>I am trying to write a Transaction Saved Search looking at estimating When new stock needs to be ordered based on the last months sales by comparing stock on hand, quantity sold, lead time, and estimated number of weeks stock on hand.</p>
  
  <p>I am running into an issue with this formula:</p>
  
  <p><code>CASE WHEN ({item.quantityonhand} / (NVL({quantity} / 30,0))) &lt; {item.locationleadtime} then 1 else 0 end</code></p>
  
  <p>The type is Formula(Numeric). I have spent ages tweaking as i was previously getting the Invalid Expression error, but i am at least now getting a result - although not the one i wanted!</p>
  
  <p>The report i have written is using Group &amp; Max summary types, and i initially had written the code with a SUM on the {quantity} field, but this doesn't appear to work. My thought was that I want the sum of quantity for all transactions for each item to be calculated.</p>
  
  <p>I have spent so long looking at this i am now out of ideas. Any help would be hugely appreciated!</p>
  
  <p>Thanks</p>
  
  <p>Mark</p>
  
  <p><a href="https://i.stack.imgur.com/aBy9r.png" rel="nofollow noreferrer">Saved Search</a></p>