簡體   English   中英

如何在 Amazon QuickSight 中創建 boolean 計算字段?

[英]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

我想創建一個 boolean 計算字段,名為“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 中創建這樣一個計算字段的方法。 請你幫助我好嗎?

預期 output:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM