Hello,
I am new to PowerShell and am playing with basic data operations and have a question about creating a lagged variable within a datatable. I know how to do this in R, or using SQL ... but what would be a good native PowerShell approach when dealing with datatables?

Below is a small example data set and the desired output below that. Note: it is lagged by group (ID).

Sure. I essentially mean to grab the value from the previous row in a time-series table.

In the example below, there are IDs A and B. Each row has a date, followed by a field that is an integer in this example. The lag is simply the value from the previous row for each ID and is shown in bold in the last column below.

So, PowerShell as a data manipulation language isn't so much a thing. Data tables in PowerShell, for example, aren't "in" PowerShell as much as they're "in" .NET Framework; PowerShell doesn't have anything native that does this. So you're obviously in .NET, but if it has some specific feature for that task, I'm afraid I don't know it (StackOverflow might be a good spot to ask). If I had to do what you're doing, I'd just save the relevant field in a variable each time through the loop, and then use that variable in setting the next row. Variables in PowerShell aren't scoped to loops, so they'll persist through each iteration.