Group by columns and add sum in new columns

Dear Experts,
I have input file which is comma separated, has 4 columns like below,

BRAND,COUNTRY,MODEL,COUNT
NIKE,USA,DUMMY,5
NIKE,USA,ORIGINAL,10
PUMA,FRANCE,DUMMY,20
PUMA,FRANCE,ORIGINAL,15
ADIDAS,ITALY,DUMMY,50
ADIDAS,ITALY,ORIGINAL,50
SPIKE,CHINA,DUMMY,1O

And expected output add one column TOTALCOUNT which is group by BRAND,COUNTRY column(1st and 2nd) and add a new column(5th) which is SUM of COUNT column(4th)..

BRAND,COUNTRY,MODEL,COUNT, TOTALCOUNT
NIKE,USA,DUMMY,5,15
NIKE,USA,ORIGINAL,10,15
PUMA,FRANCE,DUMMY,20,35
PUMA,FRANCE,ORIGINAL,15,35
ADIDAS,ITALY,DUMMY,50,100
ADIDAS,ITALY,ORIGINAL,50,100
SPIKE,CHINA,DUMMY,1O,100

What have you tried?

Welcome ricky1991,

I have a few more questions pose in response first:-

  • Is this homework/assignment? There are specific forums for these.
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)

Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

We're all here to learn and getting the relevant information will help us all.

Kind regards,
Robin