- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Use of local variable in a formula
I have a table that has a column (Samp Pt) which lists the equipment name as Equip_n where n is 1 through 9.
The Column "Date / Time" is the date and time.
The data is sorted by Equip_n and then Date / Time.
I want to create a value called Run which is the Run number for each piece of Equipment. The Run is the Equipment number-Run, e.g. 1-1. A new Run is defined when the difference between successive rows of Date/Time is greater than 190,000 seconds.
I tried using two local variables to keep track of the numerical value of the "n". It creates the first Run Value for each Equipment correctly ("1-1, "2-1", etc.) but when the successive rows are >190000 seconds apart, I get "1-.", "2-."). I'm pretty sure that I'm not using the local variables correctly. What am I doing wrong? Thank you.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Use of local variable in a formula
My error, when I pasted the formula into the response, I did not get all of the formula....I left out one line
If( Row() == 1,
hold = 1;
hold2 = 1;
,
If( :Name( "Date / Time" ) - Lag( :Name( "Date / Time" ) ) > 190000,
hold2 = hold2 + 1
);
If( :Samp Pt != Lag( :Samp Pt ),
hold = hold + 1;
hold2 = 1;
);
);
Char( hold ) || "-" || Char( hold2 );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Use of local variable in a formula
This formula appears to work
If( Row() == 1,
hold = 1;
hold2 = 1;
,
If( :Name( "Date / Time" ) - Lag( :Name( "Date / Time" ) ) > 190000,
hold2 = hold2 + 1
);
If( :Samp Pt != Lag( :Samp Pt ),
hold = hold + 1;
hold2 = 1;
);
)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Use of local variable in a formula
Thank you, but when I cut and paste your solution into the formula editor, the second and third If clauses do not have anything in the else clause. It runs but it only give the value of 1 in the first row, all others are blank. I'm running jmp (not Pro) 14.2 if that is a factor.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Use of local variable in a formula
My error, when I pasted the formula into the response, I did not get all of the formula....I left out one line
If( Row() == 1,
hold = 1;
hold2 = 1;
,
If( :Name( "Date / Time" ) - Lag( :Name( "Date / Time" ) ) > 190000,
hold2 = hold2 + 1
);
If( :Samp Pt != Lag( :Samp Pt ),
hold = hold + 1;
hold2 = 1;
);
);
Char( hold ) || "-" || Char( hold2 );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content