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
-1
votes
1 answer

Insert new column that adds a series from another column

I have a table with dates and follower growth for each date and want to make a new column that depicts total followers gained. How can I insert a new column that basically adds the 'new followers' column in to a summation series? date | new…
-1
votes
1 answer

TSQL Running total with start and end date

I have two tables, Table_A +---------+----+------------+------------+-----------+ | SurrKey | ID | StartDate | EndDate | Allotment | +---------+----+------------+------------+-----------+ | 1 | 1 | 2015-01-01 | 2015-01-31 | 1000 | | …
ggarcia
  • 47
  • 1
  • 10
-1
votes
1 answer

Loop with rolling total in c

I am trying to get a c program to ask me how many items i am buying than to ask the price for each item while keeping a rolling total and than ask again in a loop. I have the loop working fine but am having problems getting it to give me proper…
jparks54
  • 23
  • 6
-1
votes
1 answer

The sum of all the outputs (digits, the_number) is correct... it is 72, I just dont know how save it in a variable, or how to return the sum

def sumdigits(number, start): if number > 0: if start == True: new_number = ((number % 10) * 2) digits = (new_number % 10) + (new_number // 10) print(digits) sumdigits((number // 10), False) elif start ==…
-1
votes
2 answers

sum of $row based on specific time field rather than just total

This code works just fine to display a list of reservations for a given day and sums the guest and table counts just fine for the entire day. Sums all reservations returned. What I am trying to do or figure out is a way to get totals based on…
ToddG
  • 13
  • 4
-1
votes
1 answer

How to select running total for each group in a query

SELECT district_lease, first_proddate, prod_cnt, @rt := @rt + prod_cnt AS api_cnt FROM Temp1 a JOIN (SELECT @rt := 0) r GROUP BY district_lease, first_proddate ORDER BY district_lease,…
-1
votes
1 answer

To Print only the newest elements of a Hash and reporting only the changed value from the last value?

I have two lists. One is a list that only defines an instrument name. The second is the running total of that instrument. There are multiple entries in the instrument name list that are the same. I have a Hash that aggregates/prints the final…
-1
votes
1 answer

Different results each run in CUDA

I'm programming in cuda the next: I get a matrix with image values (d_Data) I copy the matrix in shared memory (tile) I get a basic pixel difference (pixel(i)-pixel(i+1)) (d_diff) If difference is a specific value for example 0, A number 1 is set i…
-1
votes
2 answers

Discount Calculation from a Range

Discount Calculation: Product quantity and range 1 - 10 - 1% 11 - 20 - 2% 21 - 30 - 3% 31 - 40 - 4% 41 - 50 - 5% the above are the quantity range and their discount% given, for example: each product cost is 100 if i…
MAHI
  • 9,263
  • 11
  • 36
  • 47
-2
votes
1 answer

Gaps and Islands but with a lot of nulls

I have source data like following table and trying to get desired output. Basically I want to running total until status changes to…
-2
votes
1 answer

Need to calculate running total

I have data like below and I need to somewhat generate running total but not really. When value changes from Green to either (Yellow or Red) then 1 for all rows until it changes again from Green to either Red or Yellow then 2 for all rows until it…
-2
votes
2 answers

One SQL statement for multiple column totals based on year

I'm trying to return the total number of unique countries listed for each year, and the total number of unique countries in the entire table. The table is formatted like this: Country | Year | State | V1 | V2 | US 2020 NY 9 2 US…
-2
votes
1 answer

How to get partial cumulative sums (of positive and negative numbers) in an array?

I have an array with positive and negative numbers and want to do a cumulative sum of numbers of the same sign until the next number carries an opposite sign. It starts again at 0. Maybe better explained with a sample. Here is the original…
tibibou
  • 164
  • 10
-2
votes
2 answers

Count consecutive row values but reset count with every 0 in row

Within a dataframe, I need to count and sum consecutive row values in column A into a new column, column B. Starting with column A, the script would count the consecutive runs in 1s but when a 0 appears it prints the total count in column B, it then…
-2
votes
1 answer

Running total by date/ID based on latest change to value SQL

I have a unique case where I want to calculate the running total of quantities day over day. I have been searching a lot but couldn't find the right answer. Code-wise, there is nothing much I can share as it refers to a lot of sensitive data Below…
Amal Sailendran
  • 341
  • 1
  • 2
  • 16