I have data where I'd like to compute the lag from one row to the next (it is a time series), but I have data for many groups. I want the lag created within each group separately. For many statistical functions (e.g., Col Mean) there is the option to add one or more By Group variables. There does not appear to be the same functionality for the Lag or Dif functions and I can't find anything in the scripting documentation to indicate how that might be done. Is there a way to easily compute the lags for each group separately? The only way I have currently found is to first sort the data by date and by group, and then use an IF formula that depends on the Group equaling the lag (Group), such as IF (Group) - lag (Group), then lag (column of interest), else missing.