cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
%3CLINGO-SUB%20id%3D%22lingo-sub-19991%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%B9%AB%E5%8A%A9%E5%89%B5%E5%BB%BA%E4%B8%80%E5%80%8B%E5%9F%BA%E6%96%BC%E5%85%B6%E4%BB%96%E5%88%97%E7%9A%84%E7%B4%AF%E7%A9%8D%E5%92%8C%E7%9A%84%E5%88%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-19991%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CP%3E%E6%88%91%E6%AD%A3%E5%9C%A8%E5%98%97%E8%A9%A6%E5%9C%A8%20JSL%20%E4%B8%AD%E5%89%B5%E5%BB%BA%E4%B8%80%E5%80%8B%E6%96%B0%E5%88%97%EF%BC%8C%E8%A9%B2%E5%88%97%E5%B0%87%E6%98%AF%E8%A9%B2%E5%88%97%E4%B8%AD%E5%89%8D%E5%B9%BE%E8%A1%8C%E7%9A%84%E6%8C%81%E7%BA%8C%E7%B8%BD%E5%92%8C%E3%80%82%E6%88%91%E6%9C%89%E4%B8%80%E5%80%8B%E5%90%8D%E7%82%BA%E2%80%9C%E6%AF%8F%E6%97%A5%E7%B8%BD%E6%B5%81%E9%87%8F%E2%80%9D%E7%9A%84%E5%88%97%EF%BC%8C%E6%88%91%E9%82%84%E6%9C%89%E4%B8%80%E5%88%97%E6%A8%99%E8%A8%98%E2%80%9C%E6%AF%8F%E6%97%A5%E7%B8%BD%E6%B5%81%E9%87%8F%E2%80%9D%E4%B8%AD%E7%9A%84%E6%95%B8%E6%93%9A%E4%BE%86%E8%87%AA%E5%93%AA%E5%80%8B%E4%BD%8D%E7%BD%AE%EF%BC%88%E7%A8%B1%E7%82%BA%E2%80%9C%E7%AB%99%E9%BB%9E%E2%80%9D%EF%BC%89%E3%80%82%E4%BE%8B%E5%A6%82%EF%BC%8C%E8%AA%AA%E6%96%BC%2010%20%E6%9C%88%201%20%E6%97%A5%EF%BC%88%E5%9C%A8%E5%8F%A6%E4%B8%80%E6%AC%84%E5%90%8D%E7%82%BA%E2%80%9C%E6%B0%B4%E5%B9%B4%E6%97%A5%E2%80%9D%EF%BC%89%E6%88%91%E6%AF%8F%E5%A4%A9%E7%9A%84%E7%B8%BD%E6%B5%81%E9%87%8F%E7%82%BA1000%EF%BC%8C%E8%80%8C%E9%80%99%E4%B8%80%E5%A4%A9%E6%81%B0%E5%A5%BD%E6%98%AF%E4%B8%80%E5%B9%B4%E4%B8%AD%E7%9A%84%E7%AC%AC%E4%B8%80%E5%A4%A9%E3%80%82%E6%88%91%E6%83%B3%E8%A6%81%E4%B8%80%E5%80%8B%E7%AC%AC%E4%B8%80%E8%A1%8C%20%3D%201000%20%E7%9A%84%E5%88%97%E3%80%82%E7%84%B6%E5%BE%8C%E8%AA%AA%E5%9C%A8%E7%AC%AC%E4%BA%8C%E5%A4%A9%EF%BC%8C%E9%80%99%E5%B0%87%E6%98%AF%E8%A1%A8%E4%B8%AD%E7%9A%84%E7%AC%AC%E4%BA%8C%E8%A1%8C%EF%BC%8C%E5%8D%B3%2010%20%E6%9C%88%202%20%E6%97%A5%EF%BC%8C%E6%AF%8F%E6%97%A5%E7%B8%BD%E6%B5%81%E9%87%8F%E7%82%BA%205000%EF%BC%8C%E6%88%91%E5%B8%8C%E6%9C%9B%E6%96%B0%E8%A1%8C%E4%B8%AD%E7%9A%84%E6%96%B0%E8%A1%8C%E5%88%97%E7%82%BA1000%20%2B%205000%20%3D%206000%E3%80%82%E7%84%B6%E5%BE%8C%E5%81%87%E8%A8%AD10%20%E6%9C%883%20%E6%97%A5%E7%9A%84%E6%AF%8F%E6%97%A5%E6%B5%81%E9%87%8F%E7%82%BA3000%EF%BC%8C%E5%9B%A0%E6%AD%A4%E4%B8%8B%E4%B8%80%E8%A1%8C%E5%B0%87%E7%82%BA6000%2B3000%20%3D%209000%E3%80%82%E9%80%99%E5%B0%8D%E6%96%BC%E6%88%91%E7%9A%84%E8%A1%A8%E4%B8%AD%E5%85%B1%E4%BA%AB%E7%9B%B8%E5%90%8C%E4%BD%8D%E7%BD%AE%E5%90%8D%E7%A8%B1%E7%9A%84%E6%AF%8F%E4%B8%80%E8%A1%8C%E9%83%BD%E9%81%A9%E7%94%A8%EF%BC%88%E7%AB%99%E9%BB%9E%EF%BC%89%E8%88%87%E2%80%9C%E6%B0%B4%E5%B9%B4%E6%97%A5%E2%80%9D%E6%AC%84%E6%8C%87%E5%AE%9A%E7%9A%84%E5%90%8C%E4%B8%80%E2%80%9C%E5%B9%B4%E2%80%9D(1-365)%E3%80%82%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-19995%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E5%B9%AB%E5%8A%A9%E5%89%B5%E5%BB%BA%E4%B8%80%E5%80%8B%E5%9F%BA%E6%96%BC%E5%85%B6%E4%BB%96%E5%88%97%E7%9A%84%E7%B4%AF%E7%A9%8D%E5%92%8C%E7%9A%84%E5%88%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-19995%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E5%BE%88%E9%AB%98%E8%88%88%E6%82%A8%E7%99%BC%E7%8F%BE%E5%AE%83%E6%9C%89%E7%94%A8%EF%BC%8C%3C%2FP%3E%3CP%3E%E4%B9%9F%E8%A8%B1%20oneliner%20%E5%8F%AF%E4%BB%A5%E5%9F%BA%E6%96%BC%E6%AD%A4%EF%BC%9A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Fmessage%2F213249%22%20target%3D%22_blank%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E8%AA%9E%E6%B3%95%EF%BC%9A%E5%A6%82%E4%BD%95%E9%80%9A%E9%81%8E%20ID%20%E5%89%B5%E5%BB%BA%E7%B4%A2%E5%BC%95%E5%88%97%3C%2FA%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%E5%AE%83%E9%82%84%E5%B0%87%E4%BD%BF%E5%85%B6%E7%8D%A8%E7%AB%8B%E6%96%BC%E6%8E%92%E5%BA%8F%E4%B8%A6%E4%BF%9D%E6%8C%81%E6%B4%BB%E8%BA%8D%E7%9A%84%E5%85%AC%E5%BC%8F%E3%80%82%3C%2FP%3E%3CP%3E%E4%BD%86%E6%88%91%E4%B8%8D%E7%9F%A5%E9%81%93%E5%A6%82%E4%BD%95%E8%A7%A3%E6%B1%BA%E5%AE%83%E3%80%82%3C%2FP%3E%3CP%3E%E6%9C%80%E5%A5%BD%E7%9A%84%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-19994%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E5%B9%AB%E5%8A%A9%E5%89%B5%E5%BB%BA%E4%B8%80%E5%80%8B%E5%9F%BA%E6%96%BC%E5%85%B6%E4%BB%96%E5%88%97%E7%9A%84%E7%B4%AF%E7%A9%8D%E5%92%8C%E7%9A%84%E5%88%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-19994%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E5%97%A8%E7%BE%85%E6%81%A9%EF%BC%8C%3C%2FP%3E%0A%3CP%3E%E9%80%99%E6%98%AF%E4%B8%80%E5%80%8B%E5%BE%88%E5%A5%BD%E7%9A%84%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%A1%88%EF%BC%8C%E6%84%9F%E8%AC%9D%E6%82%A8%E7%9A%84%E7%99%BC%E5%B8%96%E3%80%82%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%E6%96%B0%E5%88%97%20sumheightbysex%20%E7%9A%84%E5%85%AC%E5%BC%8F%E6%9C%89%E8%BC%95%E5%BE%AE%E7%9A%84%E6%8B%BC%E5%AF%AB%E9%8C%AF%E8%AA%A4%E3%80%82%20%E5%AE%83%E6%87%89%E8%A9%B2%E6%98%AF%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EIf(Row()%20%3D%3D%201%2C%20%3Aheight%2C%20%3Asex%20%3D%3D%20Lag(%3Asex%2C%201)%2C%20%3Aheight%20%2B%20Lag(%3Asumhightbysex%2C%201)%2C%20%3Asex%20!%3D%20Lag(%3Asex%2C%201)%2C%20%3Aheight%2C%20Empty())%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22p1%22%3E%E4%BD%BF%E7%94%A8%E6%96%B0%E5%88%97%E4%B8%AD%E7%9A%84%E5%80%BC%E6%B7%BB%E5%8A%A0%E5%88%B0%E9%AB%98%E5%BA%A6%EF%BC%8C%E8%80%8C%E4%B8%8D%E6%98%AF%E5%89%8D%E4%B8%80%E8%A1%8C%E7%9A%84%E9%AB%98%E5%BA%A6%EF%BC%8C%3Aheight%20%2B%20Lag(%3Aheight)%2C%201)%E3%80%82%3C%2FP%3E%0A%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22p1%22%3E%E4%BD%A0%E5%A5%BD%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-19993%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E5%B9%AB%E5%8A%A9%E5%89%B5%E5%BB%BA%E4%B8%80%E5%80%8B%E5%9F%BA%E6%96%BC%E5%85%B6%E4%BB%96%E5%88%97%E7%9A%84%E7%B4%AF%E7%A9%8D%E5%92%8C%E7%9A%84%E5%88%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-19993%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E4%BD%A0%E5%A5%BD%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Fpeople%2Faporter%22%20target%3D%22_blank%22%3E%E6%90%AC%E9%81%8B%E5%B7%A5%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3E%E5%9C%A8%E6%9B%B4%E8%81%B0%E6%98%8E%E7%9A%84%E4%BA%BA%E6%83%B3%E5%87%BA%E4%B8%80%E7%A8%AE%E5%85%A7%E8%A5%AF%E4%B9%8B%E5%89%8D%EF%BC%8C%E6%82%A8%E5%8F%AF%E4%BB%A5%E5%98%97%E8%A9%A6%E6%88%91%E7%9A%84%E6%B0%B4%E7%AE%A1%E5%B7%A5%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%A1%88%EF%BC%9A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22margin-bottom%3A%20.0001pt%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0Adt%20%3D%20Open(%20%22%24SAMPLE_DATA%2FBig%20Class.jmp%22%20)%3B%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%20%22Row%22%2C%20formula(%20%3ARow()%20)%2C%20eval%20formula%20)%3B%0Adt%3Arow%20%26lt%3B%26lt%3B%20delete%20formula%3B%0A%0A%2F%2F%20assuming%20age%20is%20time%20and%20sex%20is%20site%0Adt%20%26lt%3B%26lt%3B%20Sort(%20By(%20%3Asex%2C%20%3Aage%20)%2C%20Order(%20Ascending%2C%20Ascending%20)%2C%20replace%20table%20)%3B%0A%0A%2F%2F%20now%20sum%20as%20you%20want%20it%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%20%22sumhightbysex%22%2C%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20formula(%20If(%20Row()%20%3D%3D%201%2C%20%3Aheight%2C%20%3Asex%20%3D%3D%20Lag(%20%3Asex%2C%201%20)%2C%20%3Aheight%20%2B%20Lag(%20%3Aheight%2C%201%20)%2C%20%3Asex%20!%3D%20Lag(%20%3Asex%2C%201%20)%2C%20%3Aheight%2C%20Empty()%20)%20)%2C%20eval%20formula%0A)%3B%0Adt%3Asumhightbysex%20%26lt%3B%26lt%3B%20delete%20formula%3B%0A%0A%2F%2F%20sort%20to%20original%20order%0Adt%20%26lt%3B%26lt%3B%20Sort(%20By(%20%3ARow%20)%2C%20Order(%20Ascending%20)%2C%20replace%20table%20)%3B%0A%0A%2F%2F%20clean%20up%0Adt%20%26lt%3B%26lt%3B%20delete%20column%20(row)%3B%0ASpeak(%20%22bob's%20your%20uncle%22%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-19992%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E5%B9%AB%E5%8A%A9%E5%89%B5%E5%BB%BA%E4%B8%80%E5%80%8B%E5%9F%BA%E6%96%BC%E5%85%B6%E4%BB%96%E5%88%97%E7%9A%84%E7%B4%AF%E7%A9%8D%E5%92%8C%E7%9A%84%E5%88%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-19992%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E5%A6%82%E6%9E%9C%E6%82%A8%E9%81%8B%E8%A1%8C%E7%9A%84%E6%98%AF%20JMP%20%E7%89%88%E6%9C%AC%2012%EF%BC%8C%E4%B8%A6%E4%B8%94%E5%8F%B3%E9%8D%B5%E5%96%AE%E6%93%8A%E6%95%B8%E6%93%9A%E8%A1%A8%E4%B8%AD%E7%9A%84%E5%88%97%E6%A8%99%E9%A1%8C%E5%AD%97%E6%AE%B5%EF%BC%8C%E5%89%87%E6%96%B0%E5%85%AC%E5%BC%8F%E5%88%97%20-%26gt%3B%20%E8%A1%8C%20-%26gt%3B%20%E7%B4%AF%E7%A9%8D%E6%87%89%E8%A9%B2%E5%8F%AF%E4%BB%A5%E6%AD%A3%E5%B8%B8%E5%B7%A5%E4%BD%9C%EF%BC%8C%E8%80%8C%E7%84%A1%E9%9C%80%E6%B1%82%E5%8A%A9%E6%96%BC%20JSL%E3%80%82%20%E8%A6%8B%E4%B8%8B%E6%96%87%EF%BC%9A%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%2212442_pastedImage_0.png%22%20style%3D%22width%3A%201366px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%2212442_pastedImage_0.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%2212442_pastedImage_0.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F3592iAAC99DC5ED29D69C%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%2212442_pastedImage_0.png%22%20alt%3D%2212442_pastedImage_0.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
RVhydrA
Level III

help creating a column that is a cumulative sum based on other columns

I am trying to create a new column in JSL that will be an ongoing sum of the previous rows in that column.  I have a column called "Total Daily Flow"  I also have a column which marks what location the data in "total daily flow came from (call that "Site"). for example,  Say on Oct. 1, (which is specified in another column called "day of water year") i have a total daily flow of 1000, and this day happens to be day 1 of the year.  I want a column whose first row will be = 1000.  then say on day two, which will be the second row in the table, Oct. 2, there is a total daily flow of 5000, I would want the new row in the new column to be 1000 + 5000 = 6000.  then say Oct. 3 has a daily flow of 3000, so the next row will be 6000+3000 = 9000.  This is to go on for every row in my table that shares the same location name (Site) and is in the same "year" as specified by the column "day of water year" (1-365).

3 ACCEPTED SOLUTIONS

Accepted Solutions
Peter_Bartell
Level VIII

Re: help creating a column that is a cumulative sum based on other columns

If you are running JMP version 12, if you right click on the column header field in the data table, the New Formula Column -> Row -> Cumulative should work without having to resort to JSL. See below:

12442_pastedImage_0.png

View solution in original post

ron_horne
Super User (Alumni)

Re: help creating a column that is a cumulative sum based on other columns

hi aporter​,

until someone smarter comes up with a one liner you can try my plumbers solution:

 

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column( "Row", formula( :Row() ), eval formula );
dt:row << delete formula;

// assuming age is time and sex is site
dt << Sort( By( :sex, :age ), Order( Ascending, Ascending ), replace table );

// now sum as you want it
dt << New Column( "sumhightbysex",
     formula( If( Row() == 1, :height, :sex == Lag( :sex, 1 ), :height + Lag( :height, 1 ), :sex != Lag( :sex, 1 ), :height, Empty() ) ), eval formula
);
dt:sumhightbysex << delete formula;

// sort to original order
dt << Sort( By( :Row ), Order( Ascending ), replace table );

// clean up
dt << delete column (row);
Speak( "bob's your uncle" );

 

View solution in original post

mws
mws
Level I

Re: help creating a column that is a cumulative sum based on other columns

Hi Ron,

This is a great solution, thanks for posting.

 

The formula for the new column sumheightbysex has a slight typo. It should be

 

 

If(Row() == 1, :height, :sex == Lag(:sex, 1), :height + Lag(:sumhightbysex, 1), :sex != Lag(:sex, 1), :height, Empty())

 

 

using the value in the new column to add to the height, and not the height from previous row,  :height + Lag(:height), 1).

 

G'day

View solution in original post

4 REPLIES 4
Peter_Bartell
Level VIII

Re: help creating a column that is a cumulative sum based on other columns

If you are running JMP version 12, if you right click on the column header field in the data table, the New Formula Column -> Row -> Cumulative should work without having to resort to JSL. See below:

12442_pastedImage_0.png

ron_horne
Super User (Alumni)

Re: help creating a column that is a cumulative sum based on other columns

hi aporter​,

until someone smarter comes up with a one liner you can try my plumbers solution:

 

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column( "Row", formula( :Row() ), eval formula );
dt:row << delete formula;

// assuming age is time and sex is site
dt << Sort( By( :sex, :age ), Order( Ascending, Ascending ), replace table );

// now sum as you want it
dt << New Column( "sumhightbysex",
     formula( If( Row() == 1, :height, :sex == Lag( :sex, 1 ), :height + Lag( :height, 1 ), :sex != Lag( :sex, 1 ), :height, Empty() ) ), eval formula
);
dt:sumhightbysex << delete formula;

// sort to original order
dt << Sort( By( :Row ), Order( Ascending ), replace table );

// clean up
dt << delete column (row);
Speak( "bob's your uncle" );

 

mws
mws
Level I

Re: help creating a column that is a cumulative sum based on other columns

Hi Ron,

This is a great solution, thanks for posting.

 

The formula for the new column sumheightbysex has a slight typo. It should be

 

 

If(Row() == 1, :height, :sex == Lag(:sex, 1), :height + Lag(:sumhightbysex, 1), :sex != Lag(:sex, 1), :height, Empty())

 

 

using the value in the new column to add to the height, and not the height from previous row,  :height + Lag(:height), 1).

 

G'day

ron_horne
Super User (Alumni)

Re: help creating a column that is a cumulative sum based on other columns

glad you find it useful,

Perhaps the oneliner can be based on this:

Re: Syntax: How do I create an index column by ID

it would also make it independent of sorting and maintain an active formula.

but i am not sure how to tackle it.

Best