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

Why is the running total working only for the first declared variable?

I'm displaying a page total in the page footer of my report by using three formulas: @InitializeTotals (placed in the page header) whileprintingrecords; global currencyvar totalsssprem:=0; global currencyvar totalhdmfprem:=0; global currencyvar…
Yves
  • 682
  • 1
  • 6
  • 15
0
votes
3 answers

Can't keep running totals - ASP.NET / VB

I have an assignment to create a website that people can use to make dinner reservations. We are using Visual Basic code for the forms. It's supposed to keep running totals of each type of dinner. I'm having trouble getting the running totals to not…
Shane
  • 89
  • 2
  • 9
-1
votes
3 answers

Summing list to specific treshold with zeros trace

Is there a reasonable way to get the following done in fast compilation way? I try to sum the list of numbers to specific treshold and replace previous values to 0. I'm looking for the fastest compilation way (the list has 18 kk records). For given…
na ni
  • 1
-1
votes
2 answers

Get a Department Percent Contribution of Total Sales

Table = opportunity Dimension Field = Territory Measure Field = AnnualSales I want a measure that will take a territories SUM(AnnualSales) and see what percentage it makes of All territories SUM(AnnualSales) would be. I have not been…
-1
votes
1 answer

C# code for textbox to sum cumulative data from other textbox? (Current amount vs a running total amount)

Struggling with a C# windows form app. I've got the form built and the basic functions (can enter the values in the form fields) and they populate a listbox properly (yay!), and the textboxes clear for the next entry. This is a version of the good…
-1
votes
1 answer

Get Running Total of IDs in Presto SQL

I would like to keep a running/cumulative array of new IDs. Starting with this: Date IDs_Used_Today New_IDs Dec 6 1, 2, 3 1, 2, 3 Dec 7 1, 4 4 Dec 8 2, 3, 4 3 Dec 9 1, 2, 3, 5 5 And getting…
-1
votes
2 answers

How To Calculate Running balance using SQL

If I have total qty = 100. and it has been shipped in 4 phases line 40, 10, 25, 25 that equals to 100. when I am running this query: Someone Helped me with this query. I want the same runnable for DB2. SET totalQty = -1; SELECT IF(@totalQty<0,…
-1
votes
2 answers

SQL Coding to Categorize Data and Find Days Since Last Reported

UPDATE: This has been solved. I created a "calculated variable" in tableau called [Lab Volume] and put this code into the calculation: If [Average Results Per Day] <= 25 THEN 'Low' ELSEIF [Average Results Per Day] > 25 and [Average Results Per Day]…
-1
votes
1 answer

Issues with calculating running total in BigQuery

Not sure what the error here is but the returned result won't give the running total. I keep getting the same numbers returned for both ad_rev and running_total_ad_rev. Maybe someone could point out what the issue is? Thank…
Nata
  • 49
  • 6
-1
votes
1 answer

What is missing (while loop)?

I'm trying to sum a number like: n -> n + (n-1) + (n-2) + ... + 1. My code is working, but not doing what I wanted it to do. I would like to know if I'm missing a parameter or something like this. def s(n): a = n-1 r = 0 while a != 1: …
Marina
  • 1
  • 1
-1
votes
1 answer

PostgreSQL : syntax error in while using variable

I am trying to find cumulative sum of a column. Know that, window function can achieve this, however I want to achieve this using variables. This is my code. DECLARE csum INTEGER := 0; SELECT employee_id, department_id, boss_id, …
spb
  • 165
  • 1
  • 9
-1
votes
1 answer

Performing a cumulative sum with the loop variable itself

I want to get my code to loop so that every time it performs the calculation, it adds basically does a cumulative sum for my variable delta_omega. i.e. for every calculation, it takes the previous values in the delta_omega array, adds them together…
-1
votes
1 answer

MSSQL LOOP for calculating remaining stock with oldest price in current available stock

I am trying to figure out how to write a loop which would calculate a remaining portion of an individual items stock with oldes price... e.g. I have one Query Select Document_Date, Quantity, Price FROM ArticlesTrafic Where ArticleID = '605467' and…
-1
votes
1 answer

how to calculate sum of times in a column using foreach loop ASP.NET MVC

enter image description here suppose A is my Table and inside this table i have one column like times inside column name times i have n number of times Example :-1st:-02:30 2nd:-03:25 3rd:-00:45 i want output like TotalTime=06:40 i got out put using…
Ali
  • 1
  • 1
-1
votes
1 answer

Return the the product with highest sale for each quarter from transaction data

I have a data frame as follows. df_sample=pd.DataFrame({'ID':['ID1','ID2','ID2','ID2','ID1','ID2','ID1','ID1'], "quarter":['2016Q1','2016Q1','2016Q1','2017Q1','2017Q1','2018Q1','2018Q2','2018Q3'], …
NAS_2339
  • 353
  • 2
  • 13