Month
Country
ARPU
|-- Monthly Revenue
|-- Monthly Unique Users

UperP
|-- Monthly Unique Users
|-- Product


 character  :   Country,        Product_code,
                Payable_type,   Currency,
                Partner
             
 factor     :   Product
             
 integer    :   New_product_users,     Total_tracks,
                Rightholders_tracks,   Revenue_share
             
 numeric    :   Fee_per_month,         Active_users,
                Orchard_User_Share,    Registered_users,
                Orchard_Track_Share,   Payable,
                Payable_EUR,           Payable_USD,
                Pro_rata_share,        Net_revenue,
                Gross_revenue,         Months_committed_but_not_activated,
                Total_bundles
             
 Date       :   Month
             


cols.Categ <- c("Month", "Country", "Product", "Product_code", "Revenue_share", "Pro_rata_share", "Currency", "Payable_type", "Fee_per_month")
cols.Numer <- c("Payable", "Payable_USD", "Payable_EUR", "Active_users", "New_product_users", "Total_tracks", "Rightholders_tracks")
 Payable, Payable_USD, Payable_EUR,  Active_users, New_product_users, Total_tracks, Rightholders_tracks

(DT.Acc.Agg <- DT.Acc[, lapply(.SD, roundSum), keyby=cols.Categ, .SDcols=cols.Numer])


-------------

roundMean <- function(x) round(mean(x, na.rm=TRUE))
roundSum  <- function(x) round(sum(x, na.rm=TRUE))

DT.Acc.Last6Months <- 
DT.Acc[order(Month, decreasing=TRUE)] [Month > as.Date("2013-08-31"), 
  list( Avg_Users = roundMean(Active_users)
     ,  Avg_Rev   = roundMean(Payable)
     ,  Total_Users = roundSum(Active_users)
     ,  Total_Rev   = roundSum(Payable)
     )
  , by=Product_Tier][order(Avg_Rev, decreasing=TRUE)]

colSums(DT.Acc.Last6Months[, -1, with=FALSE])
formnumb(rbind(DT.Acc.Last6Months, data.table("---TOTAL---", NA_real_, NA_real_, roundSum(DT.Acc.Last6Months$Total_Users), roundSum(DT.Acc.Last6Months$Total_Rev)), use.names=FALSE))
