cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use to use Text Explorer to glean valuable information from text data at April 25 webinar.
Choose Language Hide Translation Bar
View Original Published Thread

Need help for using Lag function

switzal87
Level III

Hello everyone!

 

Hope someone could help me with this:

 

What is is the expected output of the following code?

123.JPG

 

After evaluation I get the following Log:

12345.JPG

 

And the new columns just looks like this:

1234.JPG

 

SliderID column is :

5.JPG

Hope someone could enlighten me with this! thanks in advance! :)

2 ACCEPTED SOLUTIONS

Accepted Solutions


Re: Need help for using Lag function

Your formula is missing an if statement. It should be something like

Formula(If(:sliderID == lag(:sliderID,1),1,0))

I would recommend you get all the steps working by using the menus and mouse clicks before trying to script it.

View solution in original post

txnelson
Super User


Re: Need help for using Lag function

Your formula

 

     :SliderID == Lag(:SiiderID, 1 )

is a boolean operation.  When the current rows value of SliderID is equal to the previous row's value os SliderID, "Lag(:SliderID, 1)", the value of the comparison will be "True" and therefore it will return a numeric value of 1.  If the comparison of the current row's value of SliderID is not equal to the previous row's value of SliderID, the returned value will be a 0.

@stephen_pearson modification of turning the formula into an "If" clause will result in the same values.

The error that is listed out, is a response to the line

 

     dABCR << Delete Rows;

and it is being returned, because no rows had been selected as a result of the line

 

     dABCR << Select Where(SN == 1);

The only correction to this line would be to scope the column reference by placing a ":" in front of SN

     dABCR << Select Where(:SN==1);
Jim

View solution in original post

5 REPLIES 5


Re: Need help for using Lag function

Your formula is missing an if statement. It should be something like

Formula(If(:sliderID == lag(:sliderID,1),1,0))

I would recommend you get all the steps working by using the menus and mouse clicks before trying to script it.

txnelson
Super User


Re: Need help for using Lag function

Your formula

 

     :SliderID == Lag(:SiiderID, 1 )

is a boolean operation.  When the current rows value of SliderID is equal to the previous row's value os SliderID, "Lag(:SliderID, 1)", the value of the comparison will be "True" and therefore it will return a numeric value of 1.  If the comparison of the current row's value of SliderID is not equal to the previous row's value of SliderID, the returned value will be a 0.

@stephen_pearson modification of turning the formula into an "If" clause will result in the same values.

The error that is listed out, is a response to the line

 

     dABCR << Delete Rows;

and it is being returned, because no rows had been selected as a result of the line

 

     dABCR << Select Where(SN == 1);

The only correction to this line would be to scope the column reference by placing a ":" in front of SN

     dABCR << Select Where(:SN==1);
Jim
Craige_Hales
Super User


Re: Need help for using Lag function

Looking at the data, I don't see any repeated SliderID values, so it might be working correctly. You might use

try(dABCE<<DeleteRows) 

to catch and ignore the error when there is nothing to delete.

 

edit: well, not try, if it isn't throwing an error. Maybe this.

Craige
switzal87
Level III


Re: Need help for using Lag function

that was enlightening! appreciated the brief explanation on how the formula works! :)
switzal87
Level III


Re: Need help for using Lag function

this worked for me! thanks a lot! :)