I'm trying to count up occurrences within subgroups and I'm a bit stuck.
I have:
Site_ID, each site can have varying rows of data
P_code, the variable I'm trying to count
Index, my new variable
The data are sorted by Site_ID and P_Code.
I need a p_code count within site.
What I have so far is
If( :p_code != Lag( :p_code, 1 ), 1, Lag( :Index, 1 ) + 1 )
This counts the p_codes within sites the way I want, but it causes 2 problems. First, it makes the first line of data missing. Second, it sometimes mis-counts. For example, if Site #11 has the same p_code as the code in the last row for Site #10, Index increases by 1 instead of starting over again at 1. How do I correct this?
Thanks