0

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)
AmanicA
  • 4,659
  • 1
  • 34
  • 49
oscarcapote
  • 417
  • 1
  • 4
  • 16

2 Answers2

2

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

groupby(@NT(sells_factor = x -> sum(x)/100),sells_table, :department; select = :package)
Bogumił Kamiński
  • 66,844
  • 3
  • 80
  • 107
1

I'd first calculate the sums and then divide them using map. See https://juliacomputing.github.io/JuliaDB.jl/latest/api/#Base.map-Tuple{Any,IndexedTables.AbstractIndexedTable}

AmanicA
  • 4,659
  • 1
  • 34
  • 49