title: How to build a rolling forward SSRS report
body: <p>I have been working on a report that would allow a user to review the totals rolling forward.</p>
  
  <p>This a is matrix.  I have included an sample on what the data looks like.</p>
  
  <p>The report should start the running total from Oct with the amount of $42.  Then the report will sum on the accounts. Then take the $42 + $64 = $106.   The $106 will carry over to the Dec month starting the beginning balance at $106.</p>
  
  <p>Report that I am working on
  <img src="https://i.stack.imgur.com/b2Kv7.png" alt="Report that I am working on"></p>
  
  <p><strong>Example of the report</strong></p>
  
  <pre><code>                     2016-011            2016-012
  
  Beginning Balance       42                   106
  
  AP                      31                    41
  APAJ                    32                    42
  CJ                      33                    43
  GEN                    -32                   -42
  
  Total Account           64                    84
  
  Begin Bal + Total Acc  106                   190
  </code></pre>
  
  <p><strong>Example of the data</strong></p>
  
  <pre><code>DECLARE @ClosingBalTemp TABLE
  (
    Account_ID varchar(30),
    Period_Nbr varchar(10),
    Source_Code varchar(10),
    Closing_Balance_Amt numeric(16,2)
  )
  
  INSERT INTO @ClosingBalTemp (Account_ID, Period_Nbr, Source_Code, Closing_Balance_Amt)
  
      VALUES ('01-002-333', '2016-008', 'AP', 1),
             ('01-002-333', '2016-008', 'APAJ', 2),
             ('01-002-333', '2016-008', 'CJ', 3),
             ('01-002-333', '2016-008', 'GEN', -2),
             ('01-002-333', '2016-009', 'AP', 11),
             ('01-002-333', '2016-009', 'APAJ', 12),
             ('01-002-333', '2016-009', 'CJ', 13),
             ('01-002-333', '2016-009', 'GEN', -12),
             ('01-002-333', '2016-010', 'AP', 20),
             ('01-002-333', '2016-010', 'APAJ', 21),
             ('01-002-333', '2016-010', 'CJ', 23),
             ('01-002-333', '2016-010', 'GEN', -22),
             ('01-002-333', '2016-011', 'AP', 31),
             ('01-002-333', '2016-011', 'APAJ', 32),
             ('01-002-333', '2016-011', 'CJ', 33),
             ('01-002-333', '2016-011', 'GEN', -32),
             ('01-002-333', '2016-012', 'AP', 41),
             ('01-002-333', '2016-012', 'APAJ', 42),
             ('01-002-333', '2016-012', 'CJ', 43),
             ('01-002-333', '2016-012', 'GEN', -42)
  
  SELECT * FROM @ClosingBalTemp
  
  
  The data should look like this
  
  The logic is almost working. The Bal type is not calculating the running balance correctly after Period 9. The 4.00 is coming from Oct that does not display.
  
  B   BAL    2016 9   4.00
  T   AP     2016 9   11.00
  T   APAJ   2016 9   12.00
  T   CJ     2016 9   13.00
  T   GEN    2016 9   -12.00
  B   BAL    2016 10  24.00     **Should be 33**
  T   AP     2016 10  20.00
  T   APAJ   2016 10  21.00
  T   CJ     2016 10  23.00
  T   GEN    2016 10  -22.00
  B   BAL    2016 11  42.00     **Should be 75**
  T   AP     2016 11  31.00
  T   APAJ   2016 11  32.00
  T   CJ     2016 11  33.00
  T   GEN    2016 11  -32.00
  B   BAL    2016 12  64.00     **Should be 139**
  T   AP     2016 12  41.00
  T   APAJ   2016 12  42.00
  T   CJ     2016 12  43.00
  T   GEN    2016 12  -42.00
  </code></pre>