如何在 Amazon QuickSight 中创建布尔计算字段?

How to create a boolean calculated field in Amazon QuickSight?

假设我可以在 QuickSight 中访问这些数据:

Id  Amount        Date
 1      10  15-01-2019
 2       0  16-01-2020
 3     100  21-12-2019
 4      34  15-01-2020
 5       5  20-02-2020
 1      50  13-09-2020
 4       0  01-01-2020

我想创建一个布尔计算字段,名为“Amount_in_2020”,当 Id 在 2020 年的总金额严格为正时,其值为 True,否则为 False。
使用 python 我会做以下事情:

# Sample data
df = pd.DataFrame({'Id' : [1,2,3,4,5,1,4],
                'Amount' : [10,0,100,34,5,50,0],
                'Date' : ['15-01-2019','16-01-2020','21-12-2019','15-01-2020','20-02-2020','13-09-2020','01-01-2020']})
df['Date']=df['Date'].astype('datetime64')

# Group by to get total amount and filter dates
df_gb = pd.DataFrame(df[(df["Date"]>="01-01-2020") & (df["Date"]<="31-12-2020")].groupby(by=["Id"]).sum()["Amount"])

# Creation of the wanted column
df["Amount_in_2020"]=np.where(df["Id"].isin(list(df_gb[df_gb["Amount"]>0].index)),True,False)

但我找不到在 Quicksight 中创建此类计算字段的方法。你能帮帮我吗?

预期输出:

Id  Amount       Date  Amount_in_2020
 1      10 2019-01-15            True
 2       0 2020-01-16           False
 3     100 2019-12-21           False
 4      34 2020-01-15            True
 5       5 2020-02-20            True
 1      50 2020-09-13            True
 4       0 2020-01-01            True

终于找到了:

ifelse(sumOver(max(ifelse(extract("YYYY",{Date})=2020,{Amount},0)), [{Id}])>0,1,0)