Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: rboccuzziHere is another way that might be helpful. Using an Agg and BRAINscript, this produces a tally for each field, but not as a seperate field, but as a string. It might be sufficient though, and you can tease that out easily later.
# For this example, we assume that the
# first field is the field that we are
# grouping on, and every other field is
# an int field we want to tally
# so this is a list of input field names
# that we are tallying and can be
# created you could populate
fieldsToTally = inputFields(1).slice(1)
# Reset counters on each new group
if firstInGroup then
tallies = list()
if lastInGroup then
result = ""
i = 0
while i < len(fieldsToTally) {
if firstInGroup then
tallies = tallies.append(0)
fname = fieldsToTally[i]
fvalue = fname.field()
cvalue = tallies[i] + fvalue
tallies = tallies.setItem(i, cvalue)
if lastInGroup then {
s = "%s : %d".format(fname, cvalue)
result = result.joinStrings(s, "; ")
}
i = i + 1
}
emit id, result
where lastInGroup