Posted by: Zeeshan Amjad | December 4, 2009

## Depreciation using Sum of Years Method

Now we are going to calculate depreciation one more method. This method is known as Sum of Years method. In this method we first sum all the years and then calculate the percentage by dividing years by the total number of years.

For example if we want to calculate the depreciation for 5 years then we first sum integer from 1 to 5. The sum is 15. And then we divide each year by 15 to calculate the depreciation value of that year.

Here is a C# code to calculate the depreciation.

```  1: double accDepreciation = 0;

2: double bookValue = cost -scrap;

3: double depExpense = 0;

4: int sum = year * (year + 1) / 2;

5: int totalYears = year;

6:

7: for (int iIndex = 0; iIndex < year; iIndex++)

8: {

9: 	double percentage = (double)totalYears / (double)sum;

10:

11: 	depExpense = bookValue * percentage;

12: 	cost -= depExpense;

13: 	accDepreciation += depExpense;

14:

15: 	DepreciationInfo dpInfo = new DepreciationInfo();

16: 	dpInfo.Year = (iIndex + 1);

17: 	dpInfo.Depreciation = depExpense;

18: 	dpInfo.AccDepreciation = accDepreciation;

19: 	dpInfo.BookValue = cost;

20: 	dpInfo.Percentage = percentage * 100;

21:

23: 	totalYears--;

24: }

25:
Here is complete XAML code of this project.
1: <Window x:Class="Depreciation.Window1"

2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

4:     Title="Depreciation" Height="400" Width="600">

5:

6:     <Grid Background="AliceBlue">

7:         <Grid.RowDefinitions>

8:             <RowDefinition/>

9:             <RowDefinition/>

10:             <RowDefinition/>

11:             <RowDefinition Height="4*"/>

12:             <RowDefinition/>

13:         </Grid.RowDefinitions>

14:

15:         <Grid.ColumnDefinitions>

16:             <ColumnDefinition/>

17:             <ColumnDefinition/>

18:         </Grid.ColumnDefinitions>

19:         <TextBlock Grid.Column="0" Grid.Row="0" Margin="5" VerticalAlignment="Center">Enter Cost of Fixed Asset</TextBlock>

20:         <TextBox Grid.Column="1" Grid.Row="0" Margin="5" VerticalAlignment="Center" Name="txtCost"></TextBox>

21:         <TextBlock Grid.Column="0" Grid.Row="1" Margin="5" VerticalAlignment="Center">Enter life Span</TextBlock>

22:         <TextBox Grid.Column="1" Grid.Row="1" Margin="5" VerticalAlignment="Center" Name="txtYear"></TextBox>

23:         <TextBlock Grid.Column="0" Grid.Row="2" Margin="5" VerticalAlignment="Center">Enter Scrap Value</TextBlock>

24:         <TextBox Grid.Column="1" Grid.Row="2" Margin="5" VerticalAlignment="Center" Name="txtScrapValue"></TextBox>

25:

26:         <ListView Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="2" Name="list" Margin="5" HorizontalContentAlignment="Stretch">

27:             <ListView.View>

28:                 <GridView>

30:                         <DataTemplate>

32:                                 <Border.Background>

37:                                 </Border.Background>

38:                                 <TextBlock Foreground="Blue" FontSize="14" FontWeight="Bold" Margin="5" Text="{Binding}" Width="Auto"/>

39:                             </Border>

40:                         </DataTemplate>

42:                     <GridViewColumn Width="Auto" Header="Year" DisplayMemberBinding="{Binding Path=Year}"/>

43:                     <GridViewColumn Width="Auto" Header="Depreciation" DisplayMemberBinding="{Binding Path=Depreciation}"/>

44:                     <GridViewColumn Width="Auto" Header="Accumulated Depreciation" DisplayMemberBinding="{Binding Path=AccDepreciation}"/>

45:                     <GridViewColumn Width="Auto" Header="Book Value" DisplayMemberBinding="{Binding Path=BookValue}"/>

47:                         <GridViewColumn.CellTemplate>

48:                             <DataTemplate>

49:                                 <ProgressBar Width="50" Height="20" Margin="5" Minimum="0" Maximum="100" Value="{Binding Percentage}"/>

50:                             </DataTemplate>

51:                         </GridViewColumn.CellTemplate>

52:                     </GridViewColumn>

53:                 </GridView>

54:             </ListView.View>

55:         </ListView>

56:         <Button Grid.Column="0" Grid.Row="4" Margin="10" Width="75" Name="btnCalculate" Click="btnCalculate_Click">Calculate</Button>

57:         <Button Grid.Column="1" Grid.Row="4" Margin="10" Width="75" Name="btnExit" Click="btnExit_Click">Exit</Button>

58:     </Grid>

59: </Window>

60:
Here is complete C# code of this program.
1: using System;

2: using System.Collections.Generic;

3: using System.Linq;

4: using System.Text;

5: using System.Windows;

6: using System.Windows.Controls;

7: using System.Windows.Data;

8: using System.Windows.Documents;

9: using System.Windows.Input;

10: using System.Windows.Media;

11: using System.Windows.Media.Imaging;

13: using System.Windows.Shapes;

14:

15: namespace Depreciation

16: {

17:     /// <summary>

18:     /// Interaction logic for Window1.xaml

19:     /// </summary>

20:     public partial class Window1 : Window

21:     {

22:         List<DepreciationInfo> depreciation;

23:         private int year;

24:         private double cost;

25:         private double scrap;

26:

27:         public Window1()

28:         {

29:             InitializeComponent();

30:

31:             depreciation = new List<DepreciationInfo>();

32:         }

33:

34:         private void btnExit_Click(object sender, RoutedEventArgs e)

35:         {

36:             Close();

37:         }

38:

39:         private void btnCalculate_Click(object sender, RoutedEventArgs e)

40:         {

41:             depreciation.Clear();

42:

43:             year = Convert.ToInt32(txtYear.Text);

44:             cost = Convert.ToDouble(txtCost.Text);

45:             scrap = Convert.ToDouble(txtScrapValue.Text);

46:

47:             if (year <= 0)

48:             {

49:                 MessageBox.Show("Number of years can not be zero or negative.");

50:                 return;

51:             }

52:

53:             if (cost <= 0 || scrap <= 0)

54:             {

55:                 MessageBox.Show("Either Cost or Scrap value is not correct.");

56:                 return;

57:             }

58:

59:             double accDepreciation = 0;

60:             double bookValue = cost -scrap;

61:             double depExpense = 0;

62:             int sum = year * (year + 1) / 2;

63:             int totalYears = year;

64:

65:             for (int iIndex = 0; iIndex < year; iIndex++)

66:             {

67:                 double percentage = (double)totalYears / (double)sum;

68:

69:                 depExpense = bookValue * percentage;

70:                 cost -= depExpense;

71:                 accDepreciation += depExpense;

72:

73:                 DepreciationInfo dpInfo = new DepreciationInfo();

74:                 dpInfo.Year = (iIndex + 1);

75:                 dpInfo.Depreciation = depExpense;

76:                 dpInfo.AccDepreciation = accDepreciation;

77:                 dpInfo.BookValue = cost;

78:                 dpInfo.Percentage = percentage * 100;

79:

81:                 totalYears--;

82:             }

83:

84:             list.ItemsSource = depreciation;

85:         }

86:     }

87:

88:     public class DepreciationInfo

89:     {

90:         public int Year

91:         { get; set; }

92:

93:         public double Depreciation

94:         { get; set; }

95:

96:         public double AccDepreciation

97:         { get; set; }

98:

99:         public double BookValue

100:         { get; set; }

101:

102:         public double Percentage

103:         { get; set; }

104:     }

105: }

106:
Here is the output of this program.

__ATA.cmd.push(function() {
__ATA.initVideoSlot('atatags-370373-5bab99cdd7d43', {
sectionId: '370373',
});
});

__ATA.cmd.push(function() {
__ATA.initSlot('atatags-26942-5bab99cdd7d86',  {
collapseEmpty: 'before',
sectionId: '26942',
width: 300,
height: 250
});
});

__ATA.cmd.push(function() {
__ATA.initSlot('atatags-114160-5bab99cdd7d89',  {
collapseEmpty: 'before',
sectionId: '114160',
width: 300,
height: 250
});
});