title: How to Reference Calculated Value from previous line to find next calculated value
body: <p>Attempting to calculate a new field based off of values in table.  Once First field is calculated need following rows the reference the previous value to begin next calculation.</p>
  
  <p>Have attempted using Lag/Lead Functions as I will need to partition.</p>
  
  <pre><code>declare @test as table (
  [Worked Hours] decimal(2,0),
  [Sold Hours] decimal(3,0),
  [Current Backlog] decimal(3,0),
  [Product] nvarchar(10),
  [Revenue Type] nvarchar(3),
  [Month] date
  )
  
  INSERT INTO @TEST 
  ([Worked Hours], [Sold Hours], [Current Backlog], [Product], [Revenue Type], [Month])
  
  VALUES
  ('10','150','50', 'Product', 'Revenue', '01-01-2019'),
  ('25','200','50', 'Product', 'Revenue', '02-01-2019'),
  ('15','175','50', 'Product', 'Revenue', '03-01-2019'),
  ('40','250','50', 'Product', 'Revenue', '04-01-2019')
  
  
  select 
  
  t.[Product],
  t.[Revenue Type],
  t.[Month],
  t.[Worked Hours],
  t.[Sold Hours],
  t.[Current Backlog]
  
  from @test as T
  </code></pre>
  
  <p>My expected Result would be a new column that would Use this Math.</p>
  
  <p>T.[Current Backlog] - T.[Worked Hours] + T.[Sold Hours] = 'New Backlog' (For the First Line this would be 190).</p>
  
  <p>The subsequent line would use the "New Backlog Value" (190) as substitution for T.[Current Backlog] in previous equation.</p>
  
  <pre><code>Overall Expected Results
  
  Product Revenue 2019-01-01  10  150 50    190
  Product Revenue 2019-02-01  25  200 50    365
  Product Revenue 2019-03-01  15  175 50    525
  Product Revenue 2019-04-01  40  250 50    735
  </code></pre>