cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
%3CLINGO-SUB%20id%3D%22lingo-sub-739077%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ECol%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-739077%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%20I%20am%20quite%20new%20to%20writing%20JMP%20scripts%20and%20primarily%20use%20%22Edit%20Formula%22%20for%20my%20work.%20I%20have%20been%20browsing%20solutions%20related%20to%20%3CSTRONG%3ECol%20Cumulative%20Sum%3C%2FSTRONG%3E%20and%20could%20not%20find%20one%20for%20my%20specific%20problem.%20The%20simplified%20version%20of%20my%20data%20table%20is%20as%20follows.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CTABLE%20border%3D%221%22%3E%3CTBODY%3E%3CTR%3E%3CTD%3E%3CSTRONG%3ERow%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EWeek%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3ECol%20Cumulative%20Sum%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EMy%20Wish%3C%2FSTRONG%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E1%3C%2FTD%3E%3CTD%3E1%3C%2FTD%3E%3CTD%3E1%3C%2FTD%3E%3CTD%3E0%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E2%3C%2FTD%3E%3CTD%3E2%3C%2FTD%3E%3CTD%3E3%3C%2FTD%3E%3CTD%3E1%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E3%3C%2FTD%3E%3CTD%3E3%3C%2FTD%3E%3CTD%3E6%3C%2FTD%3E%3CTD%3E3%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E4%3C%2FTD%3E%3CTD%3E4%3C%2FTD%3E%3CTD%3E10%3C%2FTD%3E%3CTD%3E6%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E5%3C%2FTD%3E%3CTD%3E5%3C%2FTD%3E%3CTD%3E15%3C%2FTD%3E%3CTD%3E10%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E6%3C%2FTD%3E%3CTD%3E6%3C%2FTD%3E%3CTD%3E21%3C%2FTD%3E%3CTD%3E15%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20formula%20below%20works%20if%20the%20current%20row%20value%20of%20%22Week%22%20is%20fixed%20or%20if%20I%20have%20two%20separate%20columns%20%22Week%22%20and%20%22My%20Wish.%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EIf(%20Row()%20!%3D%201%2C%0A%09Lag(%20Col%20Cumulative%20Sum(%20%3AWeek%20)%2C%201%20)%2C%0A%090%0A)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20issue%20is%20that%20the%20value%20of%20the%20previous%20row's%20%22Week%22%20is%20fixed%20but%20the%20current%20row's%20is%20not.%20And%20I%20only%20have%20one%20column%20%22Week%22%20to%20work%20with.%20I%20am%20developing%20a%20formula%20that%20simulates%20progression%20based%20on%20the%20previous%20simulation%20value.%26nbsp%3BI%20am%20simulating%20the%20current%20row's%20%22Week%22%20value%20based%20on%20the%20previous%20row's.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESuppose%20I%20am%20working%20on%20Row%204%20in%20the%20column%20%22Week.%22%20I%20want%20to%20cumulatively%20sum%20all%20the%20previous%20%22Week%22%20values%20without%20calling%20the%20current%20%22Week%22%20value%20in%20the%20function.%20Otherwise%2C%20it%20creates%20an%20illegal%20reference%20or%20cycling%20problem%20in%20my%20case.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20using%20subscript%20instead%20of%20lag%20since%20the%20lag%20function%20calls%20the%20current%20row's%20%22Week%22%20value.%20It%20did%20not%20work.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EIf(%20Row()%20!%3D%201%2C%0A%09Col%20Cumulative%20Sum(%20%3AWeek%20)%5BRow()%20-%201%5D%2C%0A%090%0A)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EI%20hope%20my%20explanation%20was%20clear%20enough.%20Thank%20you%20for%20your%20time%20and%20expertise%20in%20advance.%20I%20use%20JMP%20Pro%2017.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-739077%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EAutomation%20and%20Scripting%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPredictive%20Modeling%20and%20Machine%20Learning%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-739084%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-739084%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3E%3CP%3EYou%20can%20deduct%20current%20weeks%20value%20from%20the%20cumulative%20sum%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ECol%20Cumulative%20Sum(%3AWeek)%20-%20%3AWeek%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1711447034404.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F62678iFFD58FB05EAEE2D8%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22jthi_0-1711447034404.png%22%20alt%3D%22jthi_0-1711447034404.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-747478%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-747478%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%20I've%20been%20learning%20a%20lot%20about%20writing%20JSL%20scripts%20through%20the%20forum%20and%20watching%20lecture%20videos.%20I%20have%20a%20follow-up%20question%20regarding%20the%20following%20script.%20I%20got%20the%20same%20results%20with%20the%20second%20line.%20May%20I%20know%20why%20you%20would%20choose%20the%20first%20line%20over%20the%20second%20one%3F%20%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EEval(%20Eval%20Expr(%20casesMatrix%20%3D%20Expr(%20%3Acases%5Bi%20-%201%5D%20)%20)%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EEval(%20casesMatrix%20%3D%20%3Acases%5Bi%20-%201%5D%20%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%20Additionally%2C%20is%20there%20a%20way%20to%20avoid%20modifying%20the%20column%20%22R%22%20and%20keeping%20the%20original%20values%3F%20I%20want%20the%20modified%20R%20values%20to%20remain%20inside%20the%20column%20%22Cases%22%20without%20appearing%20anywhere.%20I%20tried%20assigning%20a%20different%20variable%20name%2C%20%22Rx%22%2C%20to%20the%20modified%20R%20as%20below.%20However%2C%20this%20approach%20requires%20me%20to%20create%20an%20empty%20column%20named%20%22Rx%22%20to%20work.%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%3ARx%20%5Bi%5D%20%3D%20%3AR%5Bi%5D%20*%20(1%20-%20(Sum(%20casesMatrix%20)%2BcasesSum)%20*%204%20%2F%20100)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EMany%20thanks%20in%20advance%20for%20your%20time%20and%20expertise.%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-739100%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-739100%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3E%3CP%3EIs%20%22Sim%20Cases%22%20a%20matrix%20or%20a%20column%20in%20a%20data%20table%3F%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%0A%3CP%3EI%20do%20not%20understand%20%3C%2FP%3E%0A%3CP%3EYou%20appear%20to%20be%20making%20your%20solution%20overly%20complex.%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Esim%20cases%20%3D%20%5B3%2C5%2C2%2C8%5D%3B%0A%0Asum1%20%3D%20sum(sim%20cases)%3B%0Asum2%20%3D%20sum((%5B1%201%201%201%5D*sim%20cases)%5B1%5D)%3B%0Ashow(sum1%2Csum2)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EBoth%20sum1%20and%20sum2%20provide%20the%20same%20value%3C%2FP%3E%0A%3CPRE%3Esum1%20%3D%2018%3B%0Asum2%20%3D%2018%3B%3C%2FPRE%3E%0A%3CP%3EI%20encourage%20you%20to%20read%20the%20Discovering%20JMP%20document%20available%20under%20the%20Help%20pull%20down%20menu.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-739315%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-739315%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3E%3CP%3EHere%20is%20my%20solution%2C%20however%2C%20it%20does%20not%20match%20your%20solution.%20%20I%20believe%20your%20calculations%20as%20shown%20are%20incorrect%20for%20Row%203.%20See%20my%20script%2C%20which%20includes%20your%20sample%20data%20table.%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0Adt%20%3D%20New%20Table(%20%22Example%22%2C%0A%09Add%20Rows(%204%20)%2C%0A%09New%20Column(%20%22R%22%2C%0A%09%09Numeric%2C%0A%09%09%22Continuous%22%2C%0A%09%09Set%20Values(%20%5B.%2C%201.4%2C%201.67%2C%202.3%5D%20)%0A%09)%2C%0A%09New%20Column(%20%22Cases%22%2C%0A%09%09Expression%2C%0A%09%09%22None%22%2C%0A%09%09Set%20Values(%20%7B%5B1%2C%201%2C%202%2C%201%5D%2C%20Empty()%2C%20Empty()%2C%20Empty()%7D%20)%0A%09)%0A)%3B%0A%0A%2F%2F%20The%20calculation%20script%0AcasesSum%20%3D%200%3B%0AFor(i%3D2%2Ci%26lt%3B%3Dnrows(dt)%2Ci%2B%2B%2C%0A%09%09Eval(%20Eval%20Expr(%20casesMatrix%20%3D%20Expr(%20%3Acases%5Bi%20-%201%5D%20)%20)%20)%3B%0A%09%09%3AR%5Bi%5D%20%3D%20%3AR%5Bi%5D%20*%20(1%20-%20(Sum(%20casesMatrix%20)%2BcasesSum)%20*%204%20%2F%20100)%3B%0A%09%09%3ACases%5Bi%5D%20%3D%20casesMatrix%20*%20%3AR%5Bi%5D%3B%0A%09%09casesSum%20%3D%20casesSum%20%2B%20sum(casesMatrix)%3B%0A)%3B%0A%0A%0A%2F%2F%20Row%203%20R%20does%20not%20seem%20to%20be%20correct%0A%2F%2F%20I%20can%20not%20come%20up%20with%20.71%2C%20I%20come%20up%20with%20.96192%0Ashow(1.4%20*%20(1%20-%20(5%20*%204%2F100))%20)%3B%20%0Ashow(1.67%20*%20(1%20-%20(10.6%20*%204%2F100))%20)%3B%20%0A%0A%0A%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22txnelson_0-1711546109146.png%22%20style%3D%22width%3A%20839px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22txnelson_0-1711546109146.png%22%20style%3D%22width%3A%20839px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22txnelson_0-1711546109146.png%22%20style%3D%22width%3A%20839px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22txnelson_0-1711546109146.png%22%20style%3D%22width%3A%20839px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22txnelson_0-1711546109146.png%22%20style%3D%22width%3A%20839px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22txnelson_0-1711546109146.png%22%20style%3D%22width%3A%20839px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22txnelson_0-1711546109146.png%22%20style%3D%22width%3A%20839px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22txnelson_0-1711546109146.png%22%20style%3D%22width%3A%20839px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22txnelson_0-1711546109146.png%22%20style%3D%22width%3A%20839px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22txnelson_0-1711546109146.png%22%20style%3D%22width%3A%20839px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22txnelson_0-1711546109146.png%22%20style%3D%22width%3A%20839px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22txnelson_0-1711546109146.png%22%20style%3D%22width%3A%20839px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F62726iC3EF6C5210F87042%2Fimage-dimensions%2F839x263%3Fv%3Dv2%22%20width%3D%22839%22%20height%3D%22263%22%20role%3D%22button%22%20title%3D%22txnelson_0-1711546109146.png%22%20alt%3D%22txnelson_0-1711546109146.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-747595%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-747595%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3E%3CP%3EYou%20suggested%202nd%20line%20is%20great.%20%20My%20reason%20for%20using%20the%20syntax%20I%20used%20is%20just%20an%20old%20habit.%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%0A%3CP%3EThe%20way%20that%20Rx%20can%20be%20used%20without%20creating%20an%20empty%20column%2C%20is%20to%20use%20it%20as%20a%20memory%20variable%20reference.%20%20Here%20is%20the%20code%20to%20do%20that%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%2F%2F%20The%20calculation%20script%0AcasesSum%20%3D%200%3B%0AFor(i%3D2%2Ci%26lt%3B%3Dnrows(dt)%2Ci%2B%2B%2C%0A%09%09Eval(%20%20casesMatrix%20%3D%20Expr(%20%3Acases%5Bi%20-%201%5D%20)%20)%3B%0A%09%09Rx%20%3D%20%3AR%5Bi%5D%20*%20(1%20-%20(Sum(%20casesMatrix%20)%2BcasesSum)%20*%204%20%2F%20100)%3B%0A%09%09%3ACases%5Bi%5D%20%3D%20casesMatrix%20*%20Rx%3B%0A%09%09casesSum%20%3D%20casesSum%20%2B%20sum(casesMatrix)%3B%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-739085%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-739085%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3E%3CP%3EThe%20moment%20I%20use%20(%3AWeek)%20in%20my%20formula%20I%20get%20an%20illegal%20reference%20problem.%20The%20current%20row%20(%3AWeek)%20has%20not%20been%20fully%20calculated%20yet.%20I%20can%20only%20recall%20(%3AWeek)%20from%20the%20previous%20row%20in%20theory.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-739086%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-739086%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3E%3CP%3EIf%20I%20am%20understanding%20correctly%2C%20I%20think%20this%20might%20be%20the%20solution%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EIf(%20Row()%20!%3D%201%2C%0A%09Sum(%20%3AWeek%5BIndex(%201%2C%20Row()%20-%201%20)%5D%20)%2C%0A%090%0A)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-739088%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-739088%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20would%20use%20separate%20columns%20to%20avoid%20all%20sorts%20of%20issues%2C%20but%20I'm%20not%20exactly%20sure%20what%20you%20are%20trying%20to%20achieve%20as%20you%20have%20full%20data%20in%20your%20example.%20Maybe%20something%20like%20this%20if%20Col%20Cumulative%20Sum%20doesn't%20work%20for%20you%20(calculate%20value%20using%20Lag%20and%20variable)%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EIf(Row()%20%3D%3D%201%2C%0A%09val%20%3D%200%2C%0A%09val%20%3D%20val%20%2B%20Lag(%3AWeek)%3B%0A)%3B%0Aval%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%20%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-739092%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-739092%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3E%3CP%3EThank%20you%20for%20your%20suggestion%20on%20using%20the%20%3CFONT%20color%3D%22%233366FF%22%3EIndex%20%3C%2FFONT%3Esubscript.%20I%20now%20encounter%20the%20issue%20%22object%20not%20subscriptable.%22%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3EMy%20%3CEM%3Eweek%3C%2FEM%3E%20example%20was%20over-simplified%20and%20I%20have%20a%20matrix%20%3CEM%3ESim%20Cases%3C%2FEM%3E%20of%204%20rows%20and%201%20column%20in%20place%20of%20%3CEM%3Eweek%3C%2FEM%3E.%20To%20transform%20it%20into%20one%20summarized%20numerical%20value%2C%20I%20multiplied%20the%20matrix%20with%20%5B1%201%201%201%5D%20and%20added%20a%20subscript%20%5B%3CFONT%20color%3D%22%23339966%22%3E1%3C%2FFONT%3E%5D.%20It%20was%20then%20followed%20by%20the%20%3CFONT%20color%3D%22%233366FF%22%3EIndex%3C%2FFONT%3E%20subscript.%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ESum(%20(%5B1%201%201%201%5D%20*%20%3ASim%20Cases)%5B1%5D%5BIndex(%201%2C%20Row()%20-%201%20)%5D%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EI%20think%20the%20resulting%20numerical%20value%20from%20the%20original%204x1%20matrix%20is%20not%20accepting%20any%20subscript%20after%20%5B%3CFONT%20color%3D%22%23339966%22%3E1%3C%2FFONT%3E%5D.%20Or%20it%20could%20be%20because%20of%20the%20illegal%20reference%20(recursion)%20again.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-739096%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-739096%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3E%3CP%3EYes%2C%20at%20first%2C%20I%20tried%20to%20emulate%20in%20the%20JMP%20data%20table%20what%20I%20usually%20do%20in%20Excel%20spreadsheets%20by%20separating%20columns.%20I%20would%20then%20call%20the%20values%20of%20the%20previous%20row%20of%20a%20different%20column.%20The%20JMP%20data%20table%20does%20not%20behave%20as%20Excel%20spreadsheets%2C%20and%20I%20am%20encountering%20cyclical%20problems.%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3ESo%2C%20I%20keep%20changing%20strategies%20and%20my%20current%20understanding%20is%20to%20keep%20every%20required%20variable%20in%20one%20column%20to%20avoid%20cyclical%20problems.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-739262%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-739262%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%20again.%20I%20am%20rephrasing%20my%20question%20in%20the%20hope%20that%20I%20can%20make%20the%20frustration%20go%20away.%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CTABLE%20border%3D%221%22%3E%3CTBODY%3E%3CTR%3E%3CTD%3ERow%3C%2FTD%3E%3CTD%3ER%3C%2FTD%3E%3CTD%3ECases%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E1%3C%2FTD%3E%3CTD%3E.%3C%2FTD%3E%3CTD%3E%5B1%2C%201%2C%202%2C%201%5D%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E2%3C%2FTD%3E%3CTD%3E1.4%3C%2FTD%3E%3CTD%3E%20%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E3%3C%2FTD%3E%3CTD%3E1.67%3C%2FTD%3E%3CTD%3E%20%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E4%3C%2FTD%3E%3CTD%3E2.3%3C%2FTD%3E%3CTD%3E%20%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%20%3C%2FP%3E%3CP%3EI%20have%202%20columns%2C%20%3CSTRONG%3E%3CEM%3ER%3C%2FEM%3E%3C%2FSTRONG%3E%20and%20%3CSTRONG%3E%3CEM%3ECases%3C%2FEM%3E%3C%2FSTRONG%3E.%20%3CEM%3ECases%3C%2FEM%3E%20are%20calculated%20by%20multiplying%20%3CEM%3E%3CSTRONG%3ER%3C%2FSTRONG%3E%3C%2FEM%3E%20from%20the%20current%20row%20with%20%3CEM%3E%3CSTRONG%3ECases%3C%2FSTRONG%3E%3C%2FEM%3E%20from%20the%20previous%20row.%20In%20addition%2C%20%3CEM%3E%3CSTRONG%3ER%20%3C%2FSTRONG%3E%3C%2FEM%3Eneeds%20to%20be%20modified%20(reduced)%20based%20on%20the%20sum%20of%20%3CEM%3E%3CSTRONG%3ECases%3C%2FSTRONG%3E%3C%2FEM%3E%20from%20the%20previous%20row.%20%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CEM%3ER%3C%2FEM%3E%3C%2FSTRONG%3E%20(row2)%20in%20column%20%3CEM%3E%3CSTRONG%3ECases%3C%2FSTRONG%3E%20%3C%2FEM%3E%3D%20%3CEM%3E%3CSTRONG%3ER%3C%2FSTRONG%3E%20%3C%2FEM%3E(row2)%20*%20modifier%3C%2FP%3E%3CP%3Emodifier%20%3D%201%20-%20%3CFONT%20color%3D%22%23000000%22%3E(%3C%2FFONT%3E%3CFONT%20color%3D%22%2300FF00%22%3E%3CFONT%20color%3D%22%23000000%22%3E(%3C%2FFONT%3E%3CFONT%20color%3D%22%23339966%22%3E%3CU%3Ecumulative%20%3C%2FU%3E%3C%2FFONT%3E%3C%2FFONT%3E%3CFONT%20color%3D%22%23339966%22%3E%3CU%3Esum%20of%20%3CEM%3E%3CSTRONG%3ECases%3C%2FSTRONG%3E%20%3C%2FEM%3Efrom%20row1%20to%20the%20row%20before%20the%20current%20row%3C%2FU%3E%3C%2FFONT%3E%20*%20%3CFONT%20color%3D%22%23FF0000%22%3E4%3C%2FFONT%3E%3CFONT%20color%3D%22%23000000%22%3E)%3C%2FFONT%3E%2F%3CFONT%20color%3D%22%23FF0000%22%3ETotal%20Population%3C%2FFONT%3E%3CFONT%20color%3D%22%23000000%22%3E)%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23000000%22%3ETotal%20Population%20is%20a%20parameter%20and%20is%20100.%20%3C%2FFONT%3E%3C%2FP%3E%3CP%3EThe%20resulting%20modifier%3CSTRONG%3E%20%3C%2FSTRONG%3Eis%20multiplied%20with%20%3CSTRONG%3E%3CEM%3ECases%3C%2FEM%3E%3C%2FSTRONG%3E%20from%20row1%20to%20create%20%3CEM%3E%3CSTRONG%3ECases%3C%2FSTRONG%3E%3C%2FEM%3E%20in%20row2.%20%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3EFor%20instance%2C%20I%20am%20expecting%20the%20modified%20%3CEM%3E%3CSTRONG%3ER%20%3C%2FSTRONG%3E%3C%2FEM%3E(row2)%3CSTRONG%3E%20%3C%2FSTRONG%3Eto%20be%201.12%20and%20%3CEM%3E%3CSTRONG%3ECases%3C%2FSTRONG%3E%20%3C%2FEM%3E(row2)%20to%20be%20%5B1.12%2C%201.12%2C%202.24%2C%201.12%5D%3C%2FP%3E%3CP%3E1.4%20*%201%20-%20(%3CFONT%20color%3D%22%23339966%22%3E%3CSTRONG%3E5%3C%2FSTRONG%3E%3C%2FFONT%3E%20*%20%3CFONT%20color%3D%22%23FF0000%22%3E4%3C%2FFONT%3E%2F%3CFONT%20color%3D%22%23FF0000%22%3E100%3C%2FFONT%3E)%20%3D%201.12%3C%2FP%3E%3CP%3E1.12%20*%20%5B1%2C%201%2C%202%2C%201%5D%20%3D%20%5B1.12%2C%201.12%2C%202.24%2C%201.12%5D%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3EThen%2C%20I%20expect%20the%20modified%20%3CEM%3E%3CSTRONG%3ER%3C%2FSTRONG%3E%3C%2FEM%3E%20(row3)%20to%20be%200.71%20and%20%3CEM%3E%3CSTRONG%3ECases%3C%2FSTRONG%3E%20%3C%2FEM%3E(row3)%20to%20be%20%5B0.8%2C%200.8%2C%201.6%2C%200.8%5D%3C%2FP%3E%3CP%3E1.67%20*%201%20-%20(%3CFONT%20color%3D%22%23339966%22%3E%3CSTRONG%3E10.6%3C%2FSTRONG%3E%3C%2FFONT%3E%20*%20%3CFONT%20color%3D%22%23FF0000%22%3E4%3C%2FFONT%3E%2F%3CFONT%20color%3D%22%23FF0000%22%3E100%3C%2FFONT%3E)%20%3D%200.71%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23339966%22%3E%3CSTRONG%3E10.6%3C%2FSTRONG%3E%3C%2FFONT%3E%20is%20from%20%3CFONT%20color%3D%22%23000000%22%3E%3CSTRONG%3E5%3C%2FSTRONG%3E%3C%2FFONT%3E%20cases%20in%20row1%20and%20%3CSTRONG%3E5.6%3C%2FSTRONG%3E%20cases%20in%20row2.%3C%2FP%3E%3CP%3E0.71%20*%20%5B1.12%2C%201.12%2C%202.24%2C%201.12%5D%20%3D%20%5B0.8%2C%200.8%2C%201.6%2C%200.8%5D%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3EI%20am%20having%20a%20problem%20in%20getting%20the%20%3CSTRONG%3E%3CFONT%20color%3D%22%23339966%22%3Egreen%3C%2FFONT%3E%3C%2FSTRONG%3E%20value.%20My%20current%20attempt%20at%20writing%20a%20JMP%20script%20is%20as%20follows.%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EIf(%20Row()%20%3D%3D%201%2C%0A%09Matrix(%20%7B1%2C%201%2C%202%2C%201%7D%20)%2C%0A%09%3AR%20*%20(1%20-%20(Summation(%20i%20%3D%201%2C%20N%20Row()%20-%201%2C%20Sum(%20%3ACases%20)%20)%20*%204)%20%2F%20Total%20Population)%20*%20Lag(%20%3ACases%2C%201%20)%0A)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%20%3C%2FP%3E%3CP%3EI%20tried%20%3CFONT%20color%3D%22%230000FF%22%3EIndex%3C%2FFONT%3E%2C%20%3CFONT%20color%3D%22%230000FF%22%3ELag%3C%2FFONT%3E%2C%20%3CFONT%20color%3D%22%230000FF%22%3ERow()%20-%201%3C%2FFONT%3E%2C%20%3CFONT%20color%3D%22%230000FF%22%3ECol%20cumulative%20sum%3C%2FFONT%3E%2C%20%3CFONT%20color%3D%22%230000FF%22%3ESummation%3C%2FFONT%3E%2C%20etc%20to%20get%20the%20modifier%2C%20and%20nothing%20has%20worked.%20I%20mainly%20get%20either%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E1)%20illegal%20referencing%20or%3C%2FP%3E%3CP%3E2)%20unsubscriptable%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3EThank%20you%20once%20again%20for%20your%20time%20and%20expertise.%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-739418%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-739418%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3E%3CP%3EThank%20you%20very%20much.%20The%20%3CFONT%20color%3D%22%233366FF%22%3Efor%3C%2FFONT%3E%20loop%20seems%20to%20be%20the%20key%20here.%20I%20have%20yet%20to%20learn%20the%20functions%2C%20%3CFONT%20color%3D%22%233366FF%22%3EEval%3C%2FFONT%3E%2C%20%3CFONT%20color%3D%22%233366FF%22%3EEval%20Expr%3C%2FFONT%3E%2C%20and%20%3CFONT%20color%3D%22%233366FF%22%3EExpr%3C%2FFONT%3E.%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3EAnd%20you%20are%20right%2C%20my%20calculations%20in%20the%20example%20were%20off.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-739101%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-739101%22%20slang%3D%22de-DE%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20will%20keep%20learning%20JMP.%20For%20now%2C%20I%20will%20just%20stick%20to%20my%20Excel%20spreadsheet.%20Thanks%20everyone%20for%20your%20responses.%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%3CEM%3ESim%20Cases%20%3C%2FEM%3Eis%20a%20column%20and%20I%20am%20using%20%3CEM%3ESim%20Cases%3C%2FEM%3E%20of%20previous%20rows%20in%20creating%20new%20rows.%20So%20I%20guess%20it%20is%20both%20a%20column%20and%20a%20variable%20inside%20that%20same%20column.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-739105%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Col%20Cumulative%20Sum%20without%20calling%20the%20current%20row's%20value%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-739105%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHow%20JMP%20tables%20and%20spreadsheets%20behave%20are%20totally%20different%20and%20this%20old%20post%20might%20be%20a%20good%20read%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FDiscussions%2FJMP-is-Not-a-Spreadsheet%2Fm-p%2F214307%23U214307%22%20class%3D%22lia-mention-container-editor-message%20lia-img-icon-forum-thread%20lia-fa-icon%20lia-fa-forum%20lia-fa-thread%20lia-fa%22%20target%3D%22_blank%22%3EJMP%20is%20Not%20a%20Spreadsheet%3C%2FA%3E%26nbsp%3Bas%20it%20provides%20some%20examples%20and%20explanation.%20You%20can%20do%20most%20of%20the%20stuff%20in%20JMP%20but%20it%20can%20take%20some%20time%20to%20get%20your%20head%20around%20how%20columns%2Brows%20behave%20in%20JMP%20vs%20single%20cell%20in%20excel.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
tMinnx
Level III

Col Cumulative Sum without calling the current row's value

Hello, I am quite new to writing JMP scripts and primarily use "Edit Formula" for my work. I have been browsing solutions related to Col Cumulative Sum and could not find one for my specific problem. The simplified version of my data table is as follows.

 

RowWeekCol Cumulative SumMy Wish
1110
2231
3363
44106
551510
662115

 

The formula below works if the current row value of "Week" is fixed or if I have two separate columns "Week" and "My Wish."

 

 

If( Row() != 1,
	Lag( Col Cumulative Sum( :Week ), 1 ),
	0
)

 

The issue is that the value of the previous row's "Week" is fixed but the current row's is not. And I only have one column "Week" to work with. I am developing a formula that simulates progression based on the previous simulation value. I am simulating the current row's "Week" value based on the previous row's.

 

Suppose I am working on Row 4 in the column "Week." I want to cumulatively sum all the previous "Week" values without calling the current "Week" value in the function. Otherwise, it creates an illegal reference or cycling problem in my case.

 

I tried using subscript instead of lag since the lag function calls the current row's "Week" value. It did not work.

 

If( Row() != 1,
	Col Cumulative Sum( :Week )[Row() - 1],
	0
)

I hope my explanation was clear enough. Thank you for your time and expertise in advance. I use JMP Pro 17.

 

 

 

15 REPLIES 15
tMinnx
Level III

Re: Col Cumulative Sum without calling the current row's value

Hello again. I am rephrasing my question in the hope that I can make the frustration go away.

 

RowRCases
1.[1, 1, 2, 1]
21.4 
31.67 
42.3 

 

I have 2 columns, R and Cases. Cases are calculated by multiplying R from the current row with Cases from the previous row. In addition, needs to be modified (reduced) based on the sum of Cases from the previous row. 

 

R (row2) in column Cases = R (row2) * modifier

modifier = 1 - ((cumulative sum of Cases from row1 to the row before the current row * 4)/Total Population)

Total Population is a parameter and is 100. 

The resulting modifier is multiplied with Cases from row1 to create Cases in row2. 

 

For instance, I am expecting the modified (row2) to be 1.12 and Cases (row2) to be [1.12, 1.12, 2.24, 1.12]

1.4 * 1 - (5 * 4/100) = 1.12

1.12 * [1, 1, 2, 1] = [1.12, 1.12, 2.24, 1.12]

 

Then, I expect the modified R (row3) to be 0.71 and Cases (row3) to be [0.8, 0.8, 1.6, 0.8]

1.67 * 1 - (10.6 * 4/100) = 0.71

10.6 is from 5 cases in row1 and 5.6 cases in row2.

0.71 * [1.12, 1.12, 2.24, 1.12] = [0.8, 0.8, 1.6, 0.8]

 

I am having a problem in getting the green value. My current attempt at writing a JMP script is as follows.

 

If( Row() == 1,
	Matrix( {1, 1, 2, 1} ),
	:R * (1 - (Summation( i = 1, N Row() - 1, Sum( :Cases ) ) * 4) / Total Population) * Lag( :Cases, 1 )
)

 

I tried Index, Lag, Row() - 1, Col cumulative sum, Summation, etc to get the modifier, and nothing has worked. I mainly get either

 

1) illegal referencing or

2) unsubscriptable

 

Thank you once again for your time and expertise.

 

txnelson
Super User

Re: Col Cumulative Sum without calling the current row's value

Here is my solution, however, it does not match your solution.  I believe your calculations as shown are incorrect for Row 3. See my script, which includes your sample data table.

Names Default To Here( 1 );
dt = New Table( "Example",
	Add Rows( 4 ),
	New Column( "R",
		Numeric,
		"Continuous",
		Set Values( [., 1.4, 1.67, 2.3] )
	),
	New Column( "Cases",
		Expression,
		"None",
		Set Values( {[1, 1, 2, 1], Empty(), Empty(), Empty()} )
	)
);

// The calculation script
casesSum = 0;
For(i=2,i<=nrows(dt),i++,
		Eval( Eval Expr( casesMatrix = Expr( :cases[i - 1] ) ) );
		:R[i] = :R[i] * (1 - (Sum( casesMatrix )+casesSum) * 4 / 100);
		:Cases[i] = casesMatrix * :R[i];
		casesSum = casesSum + sum(casesMatrix);
);


// Row 3 R does not seem to be correct
// I can not come up with .71, I come up with .96192
show(1.4 * (1 - (5 * 4/100)) ); 
show(1.67 * (1 - (10.6 * 4/100)) ); 



txnelson_0-1711546109146.png

 

Jim
tMinnx
Level III

Re: Col Cumulative Sum without calling the current row's value

Thank you very much. The for loop seems to be the key here. I have yet to learn the functions, Eval, Eval Expr, and Expr.

 

And you are right, my calculations in the example were off.

tMinnx
Level III

Re: Col Cumulative Sum without calling the current row's value

Hello, I've been learning a lot about writing JSL scripts through the forum and watching lecture videos. I have a follow-up question regarding the following script. I got the same results with the second line. May I know why you would choose the first line over the second one? 

 

Eval( Eval Expr( casesMatrix = Expr( :cases[i - 1] ) ) )
Eval( casesMatrix = :cases[i - 1]  )

 Additionally, is there a way to avoid modifying the column "R" and keeping the original values? I want the modified R values to remain inside the column "Cases" without appearing anywhere. I tried assigning a different variable name, "Rx", to the modified R as below. However, this approach requires me to create an empty column named "Rx" to work.

:Rx [i] = :R[i] * (1 - (Sum( casesMatrix )+casesSum) * 4 / 100);

Many thanks in advance for your time and expertise.

 

txnelson
Super User

Re: Col Cumulative Sum without calling the current row's value

You suggested 2nd line is great.  My reason for using the syntax I used is just an old habit.

 

The way that Rx can be used without creating an empty column, is to use it as a memory variable reference.  Here is the code to do that

// The calculation script
casesSum = 0;
For(i=2,i<=nrows(dt),i++,
		Eval(  casesMatrix = Expr( :cases[i - 1] ) );
		Rx = :R[i] * (1 - (Sum( casesMatrix )+casesSum) * 4 / 100);
		:Cases[i] = casesMatrix * Rx;
		casesSum = casesSum + sum(casesMatrix);
);
Jim
jthi
Super User

Re: Col Cumulative Sum without calling the current row's value

This script uses txnelson's solution as the starting point and makes some modifications to it. Purpose of this script is just to provide you other example for learning purposes using other techniques (For Each Row instead of For loop, gets values to matrix from :R and some other changes)

Names Default To Here(1);
dt = New Table("Example",
	Add Rows(4),
	New Column("R", Numeric, "Continuous", Set Values([., 1.4, 1.67, 2.3])),
	New Column("Cases", Expression, "None", Set Values({[1, 1, 2, 1], Empty(), Empty(), Empty()}))
);

r_m = :R << Get values;
casesSum = 0;
For Each Row(dt,
	If(Row() == 1, Continue()); // skip first row
	
	casesMatrix = Lag(:cases, 1);
	r_m[Row()] = r_m[Row()] * (1 - (Sum(casesMatrix) + casesSum) * 4 / 100);
	:Cases = casesMatrix * r_m[Row()];
	casesSum = casesSum + Sum(casesMatrix);
);
-Jarmo