# Traversing a Column with Java Snippet Simple

Hi,

I need to loop through my data set with a java snippet and create a MeasureValue column.

For example, my data looks like this

PodcastNumber,Location,Group,Metric
1,STL,1,M1
1,STL,0,M1
1,DAL,1,M1
1,DAL,0,M1
1,STL,1,M2
1,STL,0,M2
1,DAL,1,M2
1,DAL,0,M2
2,STL,1,M1
2,STL,0,M1
2,DAL,1,M1
2,DAL,0,M1
2,STL,1,M2
2,STL,0,M2
2,DAL,1,M2
2,DAL,0,M2

I need to derive a metric value for each podcast for each location for each group, and for each metric.

Something like this…
Let X = 1;
For (Podcast X in Podcasts)
For (Location X in Locations)
For (Group X in Group)
IF Metric = M1 THEN Value1 ELSE Value 2

Can somebody please help me with this?

Hi @cageybee -

If I’m understanding you correctly, don’t you just need to loop over each record in your dataset, as opposed to using a nested loop structure?

If so, you can just use the Rule Engine node, and append a Value column based on your Metric.

I can’t use math with Rule Engine and this is the reason why I am using the Java Snippet.

Would something like this be helpful?

Scott, this is where I’m at right now. I am using an IF ELSE IF ELSE in my snippet. However, it is not very efficient as I have 50 podcasts, 8 locations, 2 user groups, and 9 Metrics.

How about a set of look up tables? This depends on exactly how your value is being calculated, but e.g.

``````Podcast Number, MeasureValue
1, ...
2, ...
``````

And then

``````Location, MeasureValue
STL, ....
DAL, ....
``````

and so on…
Then, use a series of `Joiner` nodes to join your data set to the corresponding look-up tables, and finally a `Math Formula` to sort out your final MeasureValue column from the individual contributions?
Whether this works as a suggestion depends on how that MeasureValue is calculated, but your comment that

suggests something like this might work?

Steve

Thanks, Steve, I will try this to see if it will work.