title: Add new column to dataframe based on previous values and condition
body: <p>I have sample dataframe, 
  After grouping by level1 and date i got the resulted dataframe:</p>
  
  <p>val group_df = qwe.groupBy($"level1",$"date").agg(sum("rel_amount").as("amount"))</p>
  
  <pre><code>+------+----------+------+
  |level1|      date|amount|
  +------+----------+------+
  |     A|2016-03-31|   100|     
  |     A|2016-02-28|   100|     
  |     A|2016-01-31|   400|     
  |     A|2015-12-31|   500|     
  |     A|2015-11-30|  1200|     
  |     A|2015-10-31|  1300|     
  |     A|2014-12-31|   600|     
  |     B|2016-03-31|    10|     
  |     B|2016-02-28|   300|     
  |     B|2016-01-31|   423|     
  |     B|2015-12-31|   501|    
  |     B|2015-11-30|   234|    
  |     B|2015-10-31|  1234|    
  |     B|2014-12-31|  3456|    
  +------+----------+------+
  </code></pre>
  
  <p>Now I want to add extra column(previous) as year end, in this column I need to get the value for previous year end amount for each group.</p>
  
  <p>For example: for level1 :A, date=2016-03-31 the value should be 500 because it is the amount for 2015-12-31.
  Similarily, for date= 2015-12-31 the value should be 600 because the amount for 2014-12-31.Need to calculate the previous year end amount for each row.</p>
  
  <p>Expected output :</p>
  
  <pre><code>+------+----------+------+--------+
  |level1|      date|amount|Previous|
  +------+----------+------+--------+
  |     A|2016-03-31|   100|     500|
  |     A|2016-02-28|   100|     500|
  |     A|2016-01-31|   400|     500|
  |     A|2015-12-31|   500|     600|
  |     A|2015-11-30|  1200|     600|
  |     A|2015-10-31|  1300|     600|
  |     A|2014-12-31|   600|     600|
  |     B|2016-03-31|    10|     501|
  |     B|2016-02-28|   300|     501|
  |     B|2016-01-31|   423|     501|
  |     B|2015-12-31|   501|    3456|
  |     B|2015-11-30|   234|    3456|
  |     B|2015-10-31|  1234|    3456|
  |     B|2014-12-31|  3456|    3456|
  +------+----------+------+--------+
  </code></pre>
  
  <p>Can someone help me on this.</p>