每个国家/地区的最大值 cumulative_sales 的总和

aggregate product by the sum of max cumulative_sales of each country

我有一个包含变量 product_id、日期、country_id、cumulative_sales

的数据集

我需要一个计算字段,每个 product_id returns,product_id 销售的每个国家/地区的最大值 cumulative_sales 的总和。

在pseudocode/python

for prod_id in df.product_id.unique():
    list.append(
        (prod_id, 
        sum[
            max(df[product_id==prod_id and country_id==country].cumulative_sales) 
            for country in df[product_id==prod_id].country_id.unique()
           ]
         ))

创建计算字段:

{ FIXED [Product ID], [Country ID] : MAX([Cumulative Sales]) }

然后SUM那个计算字段。例如,将 [Product ID] 拖到行中,然后将计算字段拖到文本中。将聚合设置为 SUM,您应该可以开始了。