Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Balance Sheet Retained Earnings Calculation

$
0
0

Hello,

I'm trying to create a complex calculation for a metric on a Balance Sheet called Retained Earnings (pretty sure satan himself wrote this calculation).  I've been working on this for over a week now and my head hurts from hitting it against the wall.

Here's the scenario:

I have a column called Retained Earnings that is calculated by using the previous period (sometimes) and the current period (sometimes).  The rows are in sequential order by year, by month 1-12.  So, when I say previous period, it doesn't matter if we cross over years e.g. Jan 2014's previous period is December 2013.


Here we go....

Beginning of Year  Condition-  Get the previous Period's 'Closing_Entry' value  + Previous Period's Retained Earnings (if this is the first year that the company was around, then the previous period's retained earnings should be 0)


Other condition - Get Current Period's 'Record_Entry'  value+ Previous Period Retained Earnings.


The DDL is below and I will dance the jig for anyone that helps me find the right answer:).


CREATE   TABLE [dbo].[__Retained_Earnings](
    [acct_year] [smallint] NOT NULL,
    [acct_Month] [tinyint] NOT NULL,
    [prior_month] [int] NULL,
    [comp_skey] [numeric](18, 0) NOT NULL,
    [status] [varchar](6) NOT NULL,
    [CLOSE_AMT] [float] NULL,
    [OPEN_AMT] [float] NULL
) ON [PRIMARY]

Insert into [__Retained_Earnings] Values
(2006,2,200601,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2006,3,200602,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2006,4,200603,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2006,5,200604,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2006,6,200605,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2006,7,200606,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2006,8,200607,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2006,9,200608,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2006,10,200609,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2006,11,200610,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2006,12,200611,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2007,1,200612,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2007,2,200701,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2007,3,200702,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2007,4,200703,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2007,5,200704,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2007,6,200705,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2007,7,200706,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2007,8,200707,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2007,9,200708,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2007,10,200709,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2007,11,200710,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2007,12,200711,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2008,1,200712,2,'Closed',-118355.99,0)
Insert into [__Retained_Earnings] Values
(2008,2,200801,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2008,3,200802,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2008,4,200803,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2008,5,200804,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2008,6,200805,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2008,7,200806,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2008,8,200807,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2008,9,200808,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2008,10,200809,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2008,11,200810,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2008,12,200811,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2009,1,200812,2,'Closed',-795.340000000026,0)
Insert into [__Retained_Earnings] Values
(2009,2,200901,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2009,3,200902,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2009,4,200903,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2009,5,200904,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2009,6,200905,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2009,7,200906,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2009,8,200907,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2009,9,200908,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2009,10,200909,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2009,11,200910,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2009,12,200911,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2010,1,200912,2,'Closed',-297036.11,0)
Insert into [__Retained_Earnings] Values
(2010,2,201001,2,'Closed',NULL,0)
Insert into [__Retained_Earnings] Values
(2010,3,201002,2,'Closed',NULL,0)






bruce d. orr


Viewing all articles
Browse latest Browse all 23857

Trending Articles