# /Users/rsaporta/git/orch/src/MgmtReport/Accounting_vs_Analytics_2015 CTP - DT.iTunes_US_NR.r

assignWithInfo(DT.iTunes_US_NR, DT.bi_acc_with_act_date[storeid == 1 & country_code == "US" & transac_type_abbr == "NR"], info="Crop from DT.bi_acc_with_act_date restricted to just iTunes-US-NR\nLooking at revenue and how it varies according to month and is_red.\nAlso aggregating out the 'is_neg_*' columns by taking sum_abs.")
DT.iTunes_US_NR <- changeAndAggregate(DT.iTunes_US_NR, colsToAgg="revenue", colsToDrop=c("is_negative_revenue", "is_negative_units", "units", "paidunits"), addInfo="preserve", changeFunc=identity, aggFunc=sum_abs)

DT.iTunes_US_NR[, months_forward := monthsDiff(accounting_month, activity_month)]

## DROP "GIVEN" COLUMNS (including accounting_month, which is given via months_forward)
DT.iTunes_US_NR[, c("storeid", "transac_type_abbr", "country_code", "accounting_month") := NULL]

## organize
kCols.itunes <- c("is_red", "activity_month", "months_forward")
kCols.it_allmonths <- c("is_red", "activity_month")
setkeyIfNot(DT.iTunes_US_NR, kCols.itunes, organize=TRUE)

DT.iTunes_US_NR[, perc_rev_byGrp := percOfTotal(revenue), by=kCols.it_allmonths]
formnumb(DT.iTunes_US_NR, round=1)