The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum
 Origin Forum
 moving sum

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
manueljiza Posted - 04/12/2023 : 7:17:56 PM
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 2023 (Learning Edition)
Operating System: Windows 10 Pro Build 19043

Hi, I want to know if there is a way to perform a moving sum of 'n' cells of a column, with 'n' being a value defined in a cell from other column.

For example, if cell B1 = 10, sum only the values from A1 to A10. And, if cell B2 = 11, sum only the values from A2 to A11.

The formulas could look like this:

C1=total(A1:A[B1])
C2=total(A2:A[B2])
...
C[i]=total(A[i]:A[B[i]])


but it seems that indexes doesn't work in functions like sum, total, stddev...

Thanks in advance for the attention!
4   L A T E S T    R E P L I E S    (Newest First)
aplotnikov Posted - 04/13/2023 : 12:59:45 PM
1. Make the workbook window active.
2. Press Alt-3 to show the Command Line.
3. Copy the provided code and paste it to the Command Line, press Enter.
manueljiza Posted - 04/13/2023 : 12:45:15 PM
Thank you so much aplotnikov and snowli! The method of snowli works and is pretty straightforward. The code of aplotnikov is more difficult for me to apply but I'm delving into it for being able to do more complex stuff. Thanks again guys!
snowli Posted - 04/13/2023 : 11:37:11 AM
You can define a name for B1 cell and use the defined name in Column Formula.


Note: B1 should be 9 to get from A1 to A10

1. Single click on B1. A mini toolbar shows. Click the Define Name button.



2. Define a name for B1 cell, e.g. count


3. Then enter the F(x) of C to be total(A[i:i+count])
Note: The size of C will be determined by the left column of it so u will need to go to Set Column Values to set the To value to the right row number.


named range can be used in formula, fitting, etc. Read more on https://www.originlab.com/doc/en/Origin-Help/Named-Range

Thanks, Snow
aplotnikov Posted - 04/13/2023 : 06:19:08 AM
int iR;
loop(iR, 1, wks.maxRows) {
	//colB[iR]>=iR !!!!
	range rgR = col(A)[iR:$(col(B)[iR])];
	col(C)[iR] = rgR.GetSize()>1 ? total(rgR) : rgR[1];
}

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000