[英]Count rows that meet certain requirements and then subtract that number from another count
假設我有這樣的數據:
類型 | 訂單號 | 優先 | 運輸方式 |
---|---|---|---|
盒子 | 1 | 高的 | UPS |
雜項 | 1 | 高的 | UPS |
盒子 | 2 | 標准 | InstaBox |
盒子 | 3 | 標准 | UPS |
盒子 | 3 | 標准 | UPS |
盒子 | 3 | 標准 | UPS |
盒子 | 4 | 標准 | Instabox |
盒子 | 5 | 標准 | Instabox |
盒子 | 5 | 標准 | Instabox |
盒子 | 6 | 標准 | UPS |
盒子 | 7 | 標准 | UPS |
我想計算所有所謂的“私人訂單”。 它們是具有唯一訂單號和標准優先級和 UPS 交付的箱子。 (本例中有 2 個,6 和 7)然后我想計算所有具有標准優先級的框並減去所有私人訂單。 (有 9 個具有標准優先級的盒子,減去 2 個私人訂單 = 7。)
這在 Tableau 中可行嗎? 我想在文本框中顯示數字 7。
對於Private orders
請使用此字段
IF
{FIXED [Type], [Ordernumber] : COUNT([Ordernumber])} = 1
AND [Type] = 'Boxes' And [Priority] = 'Standard' And [DeliveryMethod] = 'UPS'
THEN 1 ELSE 0 END
對於所有盒子都使用這個
Sum(
If [Type] = 'Boxes' And [Priority] = 'Standard' then 1 else 0 end
)
所以對於最終的 OUTPUT 你可以直接用這個說calculation2
2
Sum(
If [Type] = 'BOXES' And [Priority] = 'Standard' then 1 else 0 END
) -
Sum(IF
{FIXED [Type], [OrderNumber] : COUNT([OrderNumber])} = 1
AND [Type] = 'BOXES' And [Priority] = 'Standard' And [DeliveryMethod] = 'UPS'
THEN 1 ELSE 0 END)
對於匹配模式,將上述字段更改為calculation3
Sum(
If [Type] = 'BOXES' And [Priority] = 'Standard' then 1 else 0 END
) -
Sum(IF
{FIXED [Type], [OrderNumber] : COUNT([OrderNumber])} = 1
AND [Type] = 'BOXES' And [Priority] = 'Standard' And REGEXP_MATCH([DeliveryMethod], "UPS")
THEN 1 ELSE 0 END)
使用的數據
結果
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.