cumulative formula

Who is online?  0 guests and 0 members
Home  »  Forums   »  microsoft business intelligence   »  sql server   » cumulative formula

cumulative formula

Topic RSS Feed

Posts under the topic: cumulative formula

Posted: 4/16/2012

Padawan 378  points  Padawan
  • Joined on: 4/3/2012
  • Posts: 189

how i can calculate cumulative formula in sql

 

i dont know formula,

 

any idea?


Posted: 4/17/2012

Jedi Knight 1516  points  Jedi Knight
  • Joined on: 1/3/2010
  • Posts: 266

hi ssrsrnew. in reporting services you have functions that do that for you.

in t-sql you can either do:

select t1.*, (select sum(amount) from table t2 where t2.modelnum=t1.modelnum and t2.month<=t1.month) [cumulative amount]
 from table t1
 order by t1.name

or

select a.manufaturer,a.modelnum,a.month,sum(b.amount) as cumulative_sum 
  from table a
          left join table b on a.modelnum=b.modelnum
where a.month>=b.month
 group by a.manufaturer,a.modelnum,a.month


Page 1 of 1 (2 items)