Questions tagged [cumulative-sum]

For questions regarding implementations or algorithms for calculating cumulative sums (also known as running totals). Always add the tag for the language/platform!

A cumulative sum (also known as a running total or partial sum) refers to the concept of maintaining only a single value (the sum), which is updated each time a new value is added to the sequence.

1433 questions
6
votes
3 answers

Mysql calculation in select statement

I have been doing my office work in Excel.and my records have become too much and want to use mysql.i have a view from db it has the columns "date,stockdelivered,sales" i want to add another calculated field know as "stock balance". i know this is…
Law
  • 129
  • 1
  • 3
  • 10
6
votes
1 answer

Select running total until specific SUM is reached

I am trying to select the first n rowid values from the following table variable that will get me as close to a sum(itemcount) of 200,000 without crossing that threshhold. If I was looking at this manually, I would just take the top 3 rows. I do not…
Snowy
  • 5,942
  • 19
  • 65
  • 119
6
votes
3 answers

mysql error when adding function

The following error is returned when trying to use a MySQL function.. #1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe…
clarkk
  • 27,151
  • 72
  • 200
  • 340
5
votes
1 answer

Pandas cumulative sum if between certain times/values

I want to insert a new column called total in final_dfwhich is a cumulative sum of value in df if it occurs between the times in final_df. It sums the values if it occurs between the start and end in final_df. So for example during the time range…
thor
  • 281
  • 1
  • 6
  • 13
5
votes
3 answers

Select where cumulative sum is less than a number (in order of priority)

I have a table with id, cost, and priority columns: create table a_test_table (id number(4,0), cost number(15,2), priority number(4,0)); insert into a_test_table (id, cost, priority) values (1, 1000000, 10); insert into a_test_table (id, cost,…
User1974
  • 276
  • 1
  • 17
  • 63
5
votes
1 answer

SQL Server - Cumulative Sum that resets when 0 is encountered

I would like to do a cumulative sum on a column, but reset the aggregated value whenever a 0 is encountered Here is an example of what i try to do : This dataset : pk price 1 10 2 15 3 0 4 10 5 5 Gives this: pk price 1 …
Maxime Lgv
  • 83
  • 2
  • 9
5
votes
1 answer

r: replace NA with 0 when calculating cumulative values

I have written a piece of code to calculate cumulative values of a variable of interest by decile. My data look like so: …
5
votes
1 answer

Label data points for cumulative plot with Gnuplot

It is straightforward to label data points in Gnuplot, in this example, I use the third column as labels for this data set (data.txt): 1 -22 "Event 0" 2 -139.7 "Event 3" 3 -11 "Event 7" 4 -35.2 "Event 6" 5 -139.7 "Event 2" 6 -139.7 "Event 4" …
smartmic
  • 661
  • 5
  • 15
5
votes
2 answers

Excel - How do I create a cumulative sum column within a group?

In Excel, I have an hours log that looks like this: PersonID Hours JobCode 1 7 1 1 6 2 1 8 3 1 10 1 2 5 3 2 3 5 2 12 2 2 4 …
Ryan
  • 53
  • 1
  • 1
  • 3
5
votes
7 answers

How to achieve running total with power query?

I want to do a running total with power query like I did with Tableau software before. Does anyone have ideas, thanks in advance!
Summer_Solstice
  • 103
  • 1
  • 2
  • 8
5
votes
3 answers

Accumulating in SQL

I have a query with results like ID, Value. What I want is to get the values in order of their ids and also calculate the accumulated value in another column. take a look at my simplified code: declare @TempTable Table ( ID int, Value…
Hosein
  • 581
  • 1
  • 7
  • 29
5
votes
4 answers

Monthly totals month returning NULL, and only outputting running total

I am using the following to try and output my monthly totals in a format such as : January Quoted Total : £678 Parts Total : £432 Profit Total : £244 February Quoted Total : £650 Parts Total : £345 Profit Total : £123 etc.......... //…
Iain Simpson
  • 8,011
  • 13
  • 47
  • 66
5
votes
6 answers

Crystal Reports: global variable running total not displaying in header

Using Crystal Reports I'm trying to display the running total of a database field in the header where all the labels are. I've attempted to do this by placing the running total (RTversion) into a formula field with the following: Shared stringvar…
phill
  • 13,434
  • 38
  • 105
  • 141
4
votes
2 answers

Calculated control on subform based on current record

I have the following: main form "customer" from a "customer" table. subform "invoices" with fields "invoice date", "invoice amount" "customer id" etc. from a table "invoices" whenever user clicks or goes to a record in the "invoices" sub form. I…
rtochip
4
votes
2 answers

Running total for each customer for a certain time period

I have two tables Customers customer customer_name 1 Headley Quincey 2 Andie Smith 3 Sarah Johnson 4 Ernest…
Mary
  • 75
  • 4