Search code examples
juliajuliadb

JuliaDB groupby: mixing sum with constants


I want to sum the elements of a table grouped by a field and then divided by a constant: For example, I have a table with department and sells and I want to sum all the sells of each department and then divide by 100 (for example). That's the code:

groupby(@NT(sells_factor = sum/100),sells_table,:department; select = :package)

Solution

  • Creating an anonymous function should work for you in one pass:

    groupby(@NT(sells_factor = x -> sum(x)/100),sells_table, :department; select = :package)