AVCO formula Guidance

punit83

Board Regular
Joined
Jan 17, 2018
Messages
84
Office Version
  1. 2019
Platform
  1. Windows
Hello !

i have created a excel for the shares i buy. i want to use formula for AVCO (Average cost method) method.
I am attaching file for reference please if some one can help me with the formula.


Stocks.xlsb
ABCDEFGHI
1#DateStatusC.Note #Scrip NameQtyT.RateT.AmountC.O.G
20110/09/21Buy9794Sun Tv10349.903,499.003,499.00
30217/09/21Buy11810Sun Tv10335.403,354.006,853.00
40322/09/21Buy13100Sun Tv20325.006,500.0013,353.00
50423/09/21Buy13773Escorts10153.001,530.001,530.00
60529/09/21Buy15139DLF10159.001,590.001,590.00
70629/09/21Sell15139Escorts-10157.00-1,570.00-1,530.00
80729/09/21Buy15139Tata Steel10466.004,660.004,660.00
90830/09/21Buy15491DLF25151.503,787.505,377.50
100930/09/21Buy15491Escorts25151.003,775.005,305.00
111030/09/21Sell15491Sun Tv-30338.50-10,155.00-10,014.75
121130/09/21Buy15491Tata Steel10457.754,577.509,237.50
131230/09/21Sell15491Tata Steel-9471.55-4,243.95-2,097.00
14Total81213.6302517,304.0537,763.25
Transaction
Cell Formulas
RangeFormula
H2:H13H2=IFERROR([@[T.Rate]]*[@Qty],"-")
I2:I13I2=IF([@Status]="BUY", (SUMIFS([T.Amount],[Scrip Name],[@[Scrip Name]],[Status],"BUY",[Date],"<="&[@Date])), (SUMIFS([T.Amount],[Scrip Name],[@[Scrip Name]],[Status],"BUY",[Date],"<"&[@Date])/SUMIFS([Qty],[Scrip Name],[@[Scrip Name]],[Status],"BUY",[Date],"<="&[@Date]))*[@Qty])
A2:A13A2=ROW(A1)
F14F14=SUBTOTAL(109,[Qty])
G14G14=IFERROR(Transaction[[#Totals],[T.Amount]]/Transaction[[#Totals],[Qty]],"-")
H14H14=SUBTOTAL(109,[T.Amount])
I14I14=SUBTOTAL(109,[C.O.G])


Thanks in Advance.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
If this is the result you are looking for, then below is the Power Query Mcode. If you are looking for something else, then provide us with a mocked up solution.
Book4
JKL
1Scrip NameStatusAverage
2Sun TvBuy4451
3EscortsBuy2652.5
4DLFBuy2688.75
5EscortsSell-1570
6Tata SteelBuy4618.75
7Sun TvSell-10155
8Tata SteelSell-4243.95
Sheet1
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"T.Rate", type number}, {"Total", type number}, {"Qty", Int64.Type}, {"Scrip Name", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Scrip Name", "Status"}, {{"Average", each List.Average([Total]), type nullable number}})
in
    #"Grouped Rows"
 
Upvote 0
If this is the result you are looking for, then below is the Power Query Mcode. If you are looking for something else, then provide us with a mocked up solution.
Book4
JKL
1Scrip NameStatusAverage
2Sun TvBuy4451
3EscortsBuy2652.5
4DLFBuy2688.75
5EscortsSell-1570
6Tata SteelBuy4618.75
7Sun TvSell-10155
8Tata SteelSell-4243.95
Sheet1
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"T.Rate", type number}, {"Total", type number}, {"Qty", Int64.Type}, {"Scrip Name", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Scrip Name", "Status"}, {{"Average", each List.Average([Total]), type nullable number}})
in
    #"Grouped Rows"
Thank you sir for reply.
i am newbie to power query.

i will try to elaborate my requirement.

For Example below is purchase of sun tv with total avg cost of 333.825/Unit x 40 Total Units = 13,353.00 Total Amount

#DateStatusC.Note #Scrip NameQtyT.RateT.AmountC.O.G
0110/09/21Buy9794Sun Tv10349.90
3,499.00​
3,499.00
0217/09/21Buy11810Sun Tv10335.40
3,354.00​
6,853.00
0322/09/21Buy13100Sun Tv20325.00
6,500.00​
13,353.00
Total40
333.825​
13,353.00​

& below is my sold of sun tv

#DateStatusC.Note #Scrip NameQtyT.RateT.AmountC.O.G
1030/09/21Sell15491Sun Tv-30338.50
-10,155.00​
-10,014.75
Total-30
338.5​
-10,155.00​
-10,014.75​

i want formula which calculates the average cost of the goods on sell date calculated from before the sales.

in above example i can get cost easily because the sales date is after all the purchase date but i am not getting answer for below table where purchase & sales are in random dates

#DateStatusC.Note #Scrip NameQtyT.RateT.AmountC.O.G
0111/01/21Buy70452.1Quick Heal30394.90
11,847.00​
11,847.00
0217/01/21Buy72217Quick Heal50374.86
18,743.00​
30,590.00
0301/04/21Sell12379Quick Heal-23275.00
-6,325.00​
-8,794.63
0404/05/21Buy26456Quick Heal10182.00
1,820.00​
32,410.00
0524/05/21Sell46610Quick Heal-10240.50
-2,405.00​
-3,601.11
0610/08/21Buy138135Quick Heal10229.00
2,290.00​
34,700.00
Total667
387.612​
25,970.00​
97,151.26​
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top