cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMPĀ® Marketplace featured Capability Explorer add-in
%3CLINGO-SUB%20id%3D%22lingo-sub-241410%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E3%83%A9%E3%82%B0%20x%20%E8%A1%8C%E3%81%AE%E5%90%88%E8%A8%88%E3%82%92%E8%A8%88%E7%AE%97%E3%81%99%E3%82%8B%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-241410%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E3%83%A9%E3%82%B0%2024%20%E8%A1%8C%E3%81%AE%E5%90%88%E8%A8%88%E3%82%92%E8%A8%88%E7%AE%97%E3%81%99%E3%82%8B%E5%88%97%E3%82%92%E4%BD%9C%E6%88%90%E3%81%97%E3%82%88%E3%81%86%E3%81%A8%E3%81%97%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%20%E3%81%93%E3%81%AE%E4%BE%8B%E3%81%A7%E3%81%AF%E3%80%81%E6%99%82%E9%96%93%E3%81%94%E3%81%A8%E3%81%AE%E9%99%8D%E6%B0%B4%E9%87%8F%E3%81%AE%E5%90%88%E8%A8%88%E3%82%92%E5%90%AB%E3%82%80%E3%80%8CPrecip%E3%80%8D%E5%88%97%E3%81%8C%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%E3%80%82%202%20%E7%95%AA%E7%9B%AE%E3%81%AE%E5%88%97%E3%80%8C%E9%99%8D%E6%B0%B4%E8%A6%B3%E6%B8%AC%E6%89%80%E3%80%8D%E3%81%AF%E3%80%81%E5%90%84%E5%80%A4%E3%81%8C%E3%81%A9%E3%81%AE%E5%A0%B4%E6%89%80%E3%81%8B%E3%82%89%E8%A8%98%E9%8C%B2%E3%81%95%E3%82%8C%E3%81%9F%E3%81%8B%E3%82%92%E7%A4%BA%E3%81%97%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%20%E3%80%8C%E6%97%A5%E4%BB%98%E6%99%82%E5%88%BB%E3%80%8D%E3%81%A8%E3%80%8C%E9%99%8D%E6%B0%B4%E8%A6%B3%E6%B8%AC%E6%89%80%E3%80%8D%E3%81%AB%E5%9F%BA%E3%81%A5%E3%81%84%E3%81%A6%E5%88%97%E3%82%92%E4%B8%A6%E3%81%B9%E6%9B%BF%E3%81%88%E3%81%BE%E3%81%97%E3%81%9F%E3%80%82%20Precip%20%E5%88%97%E3%81%AE%E5%89%8D%E3%81%AE%2024%20%E5%80%8B%E3%81%AE%E5%80%A4%E3%82%92%E5%90%88%E8%A8%88%E3%81%97%E3%81%A6%E3%80%81%E9%81%8E%E5%8E%BB%2024%20%E6%99%82%E9%96%93%E3%81%AB%E9%99%8D%E3%81%A3%E3%81%9F%E9%9B%A8%E3%81%AE%E9%87%8F%E3%82%92%E7%A4%BA%E3%81%99%E6%96%B0%E3%81%97%E3%81%84%E5%88%97%E3%82%92%E4%BD%9C%E6%88%90%E3%81%99%E3%82%8B%E5%8A%B9%E7%8E%87%E7%9A%84%E3%81%AA%E6%96%B9%E6%B3%95%E3%82%92%E6%8E%A2%E3%81%97%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%20%E3%81%93%E3%81%AE%2024%20%E6%99%82%E9%96%93%E3%81%AE%E5%90%88%E8%A8%88%E3%81%AF%E3%82%B9%E3%83%86%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E5%9B%BA%E6%9C%89%E3%81%A7%E3%81%82%E3%82%8B%E3%81%9F%E3%82%81%E3%80%81%E3%83%A9%E3%82%B0%2024%20%E3%81%AE%E9%99%8D%E6%B0%B4%E9%87%8F%E3%81%8C%E4%B8%80%E8%87%B4%E3%81%97%E3%81%AA%E3%81%84%E5%A0%B4%E5%90%88%E3%81%AF%E3%83%A9%E3%82%B0%2024%20%E3%81%AE%E5%80%A4%E3%82%92%E8%A8%88%E7%AE%97%E3%81%A7%E3%81%8D%E3%81%BE%E3%81%9B%E3%82%93%E3%80%82%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-241590%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20%E3%83%A9%E3%82%B0%20x%20%E8%A1%8C%E3%81%AE%E5%90%88%E8%A8%88%E3%82%92%E8%A8%88%E7%AE%97%E3%81%99%E3%82%8B%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-241590%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E7%A7%81%E3%81%AF%E3%81%93%E3%82%8C%E3%82%92%E8%87%AA%E5%88%86%E3%81%A7%E7%90%86%E8%A7%A3%E3%81%99%E3%82%8B%E3%81%93%E3%81%A8%E3%81%AB%E3%81%AA%E3%82%8A%E3%81%BE%E3%81%97%E3%81%9F%E3%80%82%E3%81%93%E3%82%8C%E3%81%AF%E5%8D%98%E7%B4%94%E3%81%AA%E5%90%88%E8%A8%88%E9%96%A2%E6%95%B0%E3%81%A7%E3%81%99%E3%80%82%20%E4%BB%96%E3%81%AE%E8%AA%B0%E3%81%8B%E3%81%8C%E3%81%93%E3%81%AE%E3%82%88%E3%81%86%E3%81%AA%E3%81%93%E3%81%A8%E3%82%92%E3%81%99%E3%82%8B%E5%BF%85%E8%A6%81%E3%81%8C%E3%81%82%E3%82%8B%E5%A0%B4%E5%90%88%E3%81%AB%E5%82%99%E3%81%88%E3%81%A6%E6%8A%95%E7%A8%BF%E3%81%99%E3%82%8B%E3%81%A8%E6%80%9D%E3%81%84%E3%81%BE%E3%81%97%E3%81%9F%E3%80%82%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(%20%3APrecipitation%20Station%20%3D%3D%20Lag(%20%3APrecipitation%20Station%2C%201%20)%2C%0A%20Summation(%20i%20%3D%201%2C%2024%2C%20Lag(%20%3APrecipitation%2C%20i%20)%20)%2C%0A%20%3APrecipitation%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-241437%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20%E3%83%A9%E3%82%B0%20x%20%E8%A1%8C%E3%81%AE%E5%90%88%E8%A8%88%E3%82%92%E8%A8%88%E7%AE%97%E3%81%99%E3%82%8B%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-241437%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E5%AE%9F%E9%9A%9B%E3%81%AB%E3%81%AF%E3%80%81%E7%89%B9%E5%AE%9A%E3%81%AE%E3%82%B9%E3%83%86%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%2F%E6%97%A5%E4%BB%98%E3%81%AE%E5%90%88%E8%A8%88%E9%99%8D%E6%B0%B4%E9%87%8F%E3%82%92%E8%A8%88%E7%AE%97%E3%81%97%E3%82%88%E3%81%86%E3%81%A8%E3%81%97%E3%81%A6%E3%81%84%E3%82%8B%E3%81%AE%E3%81%A7%E3%81%AF%E3%81%AA%E3%81%8F%E3%80%81%E3%82%B9%E3%83%86%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%2F%E9%81%8E%E5%8E%BB%2024%20%E6%99%82%E9%96%93%E3%81%AE%E5%90%88%E8%A8%88%E9%99%8D%E6%B0%B4%E9%87%8F%E3%82%92%E8%A8%88%E7%AE%97%E3%81%97%E3%82%88%E3%81%86%E3%81%A8%E3%81%97%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%E3%81%97%E3%81%9F%E3%81%8C%E3%81%A3%E3%81%A6%E3%80%81%E3%81%9F%E3%81%A8%E3%81%88%E3%81%B0%E3%80%81%E6%8C%87%E5%AE%9A%E3%81%95%E3%82%8C%E3%81%9F%20for%20%E3%81%AE%20DateTime%20%E3%81%8C%201%2F3%2F2020%2009%3A00%3A00%20AM%20%E3%81%A7%E3%81%82%E3%82%8B%E5%A0%B4%E5%90%88%E3%80%81precip%20%E5%88%97%E3%81%AE%E5%89%8D%E3%81%AE%2024%20%E5%80%8B%E3%81%AE%E5%80%A4%E3%82%92%E5%8F%96%E5%BE%97%E3%81%97%E3%80%81%E3%81%9D%E3%82%8C%E3%82%89%E3%82%92%E5%90%88%E8%A8%88%E3%81%97%E3%81%9F%E3%81%84%E3%81%A8%E8%80%83%E3%81%88%E3%81%BE%E3%81%99%E3%80%82%20%E3%81%A4%E3%81%BE%E3%82%8A%E3%80%812020%20%E5%B9%B4%201%20%E6%9C%88%203%20%E6%97%A5%E3%81%AE%E5%8D%88%E5%89%8D%208%3A00%3A00%20%E3%81%8B%E3%82%89%E5%A7%8B%E3%81%BE%E3%82%8A%E3%80%812020%20%E5%B9%B4%201%20%E6%9C%88%202%20%E6%97%A5%E3%81%AE%E5%8D%88%E5%89%8D%209%3A00%3A00%20%E3%81%BE%E3%81%A7%E9%81%A1%E3%82%8A%E3%81%BE%E3%81%99%E3%80%82%E5%9F%BA%E6%9C%AC%E7%9A%84%E3%81%AB%E3%81%AF%2024%20%E6%99%82%E9%96%93%E3%81%AE%E7%A7%BB%E5%8B%95%E6%99%82%E9%96%93%E6%9E%A0%E3%81%A7%E3%81%99%E3%80%82%20%E3%81%97%E3%81%9F%E3%81%8C%E3%81%A3%E3%81%A6%E3%80%81%E3%81%93%E3%81%AE%E5%88%97%E3%81%AB%E3%81%AF%E3%80%81%E3%83%87%E3%83%BC%E3%82%BF%20%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E3%81%AE%E5%90%84%E8%A1%8C%E3%81%AE%E9%81%8E%E5%8E%BB%2024%20%E6%99%82%E9%96%93%E3%81%AE%E9%9B%A8%E3%81%8C%E8%A1%A8%E7%A4%BA%E3%81%95%E3%82%8C%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-241436%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20%E3%83%A9%E3%82%B0%20x%20%E8%A1%8C%E3%81%AE%E5%90%88%E8%A8%88%E3%82%92%E8%A8%88%E7%AE%97%E3%81%99%E3%82%8B%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-241436%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Precip.png%22%20style%3D%22width%3A%20734px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Precip.png%22%20style%3D%22width%3A%20734px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Precip.png%22%20style%3D%22width%3A%20734px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F21000iD4CFF40B4B8FBF7D%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Precip.png%22%20alt%3D%22Precip.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-241434%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20%E3%83%A9%E3%82%B0%20x%20%E8%A1%8C%E3%81%AE%E5%90%88%E8%A8%88%E3%82%92%E8%A8%88%E7%AE%97%E3%81%99%E3%82%8B%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-241434%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E7%89%B9%E5%AE%9A%E3%81%AE%E6%97%A5%2F%E8%A6%B3%E6%B8%AC%E7%82%B9%E3%81%AE%E9%99%8D%E6%B0%B4%E9%87%8F%E3%81%AE%E5%90%88%E8%A8%88%E3%82%92%E8%A8%88%E7%AE%97%E3%81%97%E3%82%88%E3%81%86%E3%81%A8%E3%81%97%E3%81%A6%E3%81%84%E3%82%8B%E5%A0%B4%E5%90%88%E3%81%AF%E3%80%81%E6%97%A5%E6%99%82%E3%81%AE%E6%97%A5%E4%BB%98%E9%83%A8%E5%88%86%E3%81%A0%E3%81%91%E3%82%92%E5%90%AB%E3%82%80%E6%96%B0%E3%81%97%E3%81%84%E5%88%97%E3%82%92%E4%BD%9C%E6%88%90%E3%81%97%E3%81%BE%E3%81%99%E3%80%82%E6%AC%A1%E3%81%AB%E3%80%81%E6%97%A5%E4%BB%98%E3%81%A8%E9%A7%85%E3%81%94%E3%81%A8%E3%81%AB%E9%9B%86%E8%A8%88%E3%82%92%E8%A1%8C%E3%81%84%E3%80%81Precip%20%E3%82%92%E7%9C%9F%E3%82%93%E4%B8%AD%E3%81%AB%E7%BD%AE%E3%81%8D%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%0A%3CP%3E%E3%81%93%E3%81%AE%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%81%AF%E3%80%81%E6%97%A5%E4%BB%98%E3%81%AE%E6%95%B0%E5%BC%8F%E5%88%97%E3%82%92%E5%90%AB%E3%82%80%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%20%E3%83%87%E3%83%BC%E3%82%BF%E3%82%BB%E3%83%83%E3%83%88%E3%81%A8%E3%80%81%E6%97%A5%E4%BB%98%2F%E8%A6%B3%E6%B8%AC%E6%89%80%E3%81%94%E3%81%A8%E3%81%AE%E9%99%8D%E6%B0%B4%E9%87%8F%E3%82%92%E8%A8%88%E7%AE%97%E3%81%99%E3%82%8B%E3%81%9F%E3%82%81%E3%81%AE%E8%A1%A8%E4%BD%9C%E6%88%90%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%82%92%E4%BD%9C%E6%88%90%E3%81%97%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENew%20Table(%20%22Example%22%2C%20Add%20Rows(%2020%20)%2C%0A%20New%20Script(%20%22Tabulate%22%2C%20%0A%20%20Tabulate(%0A%20%20%20Show%20Control%20Panel(%200%20)%2C%0A%20%20%20Add%20Table(%0A%20%20%20%20Column%20Table(%20Analysis%20Columns(%20%3APrecip%20)%20)%2C%0A%20%20%20%20Row%20Table(%20Grouping%20Columns(%20%3APrecip%20Date%2C%20%3AStation%20)%20)%0A%20%20%20)%0A%20%20)%0A%20)%2C%0A%20New%20Column(%20%22Precip%20Datetime%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%20%22ddMonyyyy%20h%3Am%3As%22%2C%2022%2C%200%20)%2C%0A%20%20Input%20Format(%20%22ddMonyyyy%20h%3Am%3As%22%2C%200%20)%2C%0A%20%20Set%20Values(%0A%20%20%20%5B3660710400%2C%203660714000%2C%203660717600%2C%203660721200%2C%203660724800%2C%203660710400%2C%0A%20%20%203660714000%2C%203660717600%2C%203660721200%2C%203660724800%2C%203660796800%2C%203660800400%2C%0A%20%20%203660804000%2C%203660807600%2C%203660811200%2C%203660796800%2C%203660800400%2C%203660804000%2C%0A%20%20%203660807600%2C%203660811200%5D%0A%20%20)%2C%0A%20%20Set%20Display%20Width(%20186%20)%0A%20)%2C%0A%20New%20Column(%20%22Station%22%2C%20Character%2C%20%22Nominal%22%2C%0A%20%20Set%20Values(%0A%20%20%20%7B%22A%22%2C%20%22A%22%2C%20%22A%22%2C%20%22A%22%2C%20%22A%22%2C%20%22B%22%2C%20%22B%22%2C%20%22B%22%2C%20%22B%22%2C%20%22B%22%2C%20%22A%22%2C%20%22A%22%2C%20%22A%22%2C%20%22A%22%2C%0A%20%20%20%22A%22%2C%20%22B%22%2C%20%22B%22%2C%20%22B%22%2C%20%22B%22%2C%20%22B%22%7D%0A%20%20)%0A%20)%2C%0A%20New%20Column(%20%22Precip%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%20%22Best%22%2C%2012%20)%2C%0A%20%20Set%20Values(%20%5B1%2C%202%2C%203%2C%204%2C%205%2C%203%2C%204%2C%205%2C%201%2C%201%2C%204%2C%205%2C%206%2C%207%2C%205%2C%204%2C%205%2C%206%2C%207%2C%208%5D%20)%0A%20)%2C%0A%20New%20Column(%20%22Precip%20Date%22%2C%20Character%2C%20%22Nominal%22%2C%0A%20%20Formula(%20Short%20Date(%20%3APrecip%20Datetime%20)%20)%0A%20)%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
RVhydrA
Level III

calculating sum of lag x rows

I am trying to create a column that calculates the sum of the lag 24 rows. In this instance I have a column "Precip" that contains hourly precipitation totals. There is a second column  "precipitation station" denoting from which location each value was recorded. I have sorted the columns based on "DateTime" and the "Precipitation Station". I am looking for an efficient way to sum the previous 24 values in the Precip column thus creating a new column that tells me how much it rained in the previous 24 hours. This 24 hour total is station specific so it cannot calculate the lag 24 values if the lag 24 precipitations do not match. 

1 ACCEPTED SOLUTION

Accepted Solutions
RVhydrA
Level III

Re: calculating sum of lag x rows

I ended up figuring this out on my own, it is a simple summation function. Figured i'd post it in case anyone else needs to do something like this. 

 

 

If( :Precipitation Station == Lag( :Precipitation Station, 1 ),
	Summation( i = 1, 24, Lag( :Precipitation, i ) ),
	:Precipitation
);

 

 

View solution in original post

4 REPLIES 4
pmroz
Super User

Re: calculating sum of lag x rows

If you are trying to calculate the sum of precipitation for a given day/station, create a new column which is just the date part of the datetime.  Then do a tabulation by date and station, and put Precip in the middle.

This program creates an example dataset with a formula column for date and a Tabulate program to calculate the precipitation by date/station.

New Table( "Example", Add Rows( 20 ),
	New Script( "Tabulate", 
		Tabulate(
			Show Control Panel( 0 ),
			Add Table(
				Column Table( Analysis Columns( :Precip ) ),
				Row Table( Grouping Columns( :Precip Date, :Station ) )
			)
		)
	),
	New Column( "Precip Datetime", Numeric, "Continuous", Format( "ddMonyyyy h:m:s", 22, 0 ),
		Input Format( "ddMonyyyy h:m:s", 0 ),
		Set Values(
			[3660710400, 3660714000, 3660717600, 3660721200, 3660724800, 3660710400,
			3660714000, 3660717600, 3660721200, 3660724800, 3660796800, 3660800400,
			3660804000, 3660807600, 3660811200, 3660796800, 3660800400, 3660804000,
			3660807600, 3660811200]
		),
		Set Display Width( 186 )
	),
	New Column( "Station", Character, "Nominal",
		Set Values(
			{"A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "A", "A", "A", "A",
			"A", "B", "B", "B", "B", "B"}
		)
	),
	New Column( "Precip", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 2, 3, 4, 5, 3, 4, 5, 1, 1, 4, 5, 6, 7, 5, 4, 5, 6, 7, 8] )
	),
	New Column( "Precip Date", Character, "Nominal",
		Formula( Short Date( :Precip Datetime ) )
	)
);
pmroz
Super User

Re: calculating sum of lag x rows

Precip.png

RVhydrA
Level III

Re: calculating sum of lag x rows

I'm not actually trying to compute the total precip for a given station/date, but rather station/previous 24 hour period. so for example if the DateTime for a given for is 1/3/2020 09:00:00 AM I would want to take the previous 24 values in the precip column and sum those. So starting with 1/3/2020 08:00:00AM and going all the way back to 1/2/2020 09:00:00 AM. Essentially a moving 24 hour window of time. This column would thus give me the previous rain over the prior 24 hours for each row in my data table.

RVhydrA
Level III

Re: calculating sum of lag x rows

I ended up figuring this out on my own, it is a simple summation function. Figured i'd post it in case anyone else needs to do something like this. 

 

 

If( :Precipitation Station == Lag( :Precipitation Station, 1 ),
	Summation( i = 1, 24, Lag( :Precipitation, i ) ),
	:Precipitation
);