How do I check for duplicate rows and do calculate on that rows in excel file? -
i have 1 excel file having data following
cusip quantity date price af0 500000 5/6/2013 1 ae4 400000 5/6/2013 1.0825 ae4 500 5/6/2013 1
i need check column cusip
, date
if i'm having duplicate cusip
same date
need following calculation.
1.need add
quantity
both of them instead of showing duplicate records need show 1 record( sum of quantity).2.need calculation on price following
newprice = ((400000 * 1.0825) + (500 * 1.00))/(400000 + 500) = 1.08148
for example in using above data need show output
cusip quantity date price af0 500000 5/6/2013 1 ae4 400500 5/6/2013 1.082397004
how achieve in excel file using lookup or else ?
okay, after quite research (interesting question way!), came this:
=if(countif($a$2:a2,a2)>1,"",sumif(a:a,a2,b:b)) =if(countif($a$2:a2,a2)>1,"",sumproduct(--(a:a=a2),b:b,d:d)/sumif(a:a,a2,b:b))
put these in cell d2 , e2 respectively (which next column after price
, in row of cusip af0
).
and fill bottom of worksheet weighted average price or each cusip.
the first formula gives total quantity cusip , second gives average price.
copy , paste values 2 columns after calculation.
put filter , remove rows total quantity , average price blank, , sort make worksheet neat.
let me know if works you! tried on sample data , seems working. it's first time using sumproduct
^^;
sumproduct(--(a:a=a2)
this bit returns rows column equals row's cusip.
sumproduct(--(a:a=a2),b:b,d:d
this additional bit tells excel multiply values in column b , d of each returned row found above , sumproduct
adds each result together.
edit: forgot date. maybe add helper column you'll generate identifier separate different dates. make it, you'll have make concatenate
.
hence in cell f2, put:
=concatenate(a2,c2)
in formulae cells d2 , e2, have change them become:
=if(countif($f$2:f2,f2)>1,"",sumif(a:a,a2,b:b)) =if(countif($f$2:f2,f2)>1,"",sumproduct(--(a:a=a2),b:b,d:d)/sumif(a:a,a2,b:b))
reedit: oops, put wrong reference. fixed now.
Comments
Post a Comment