2015-09-27 4375 views
1

我正在嘗試在Tableau中執行以下操作。解決Tableau中IF結果的聚合和非聚合混合錯誤

如果選擇的關鍵人物是銷售或體積(非集合字段),然後調用計算1其他計算2.

IF ATTR([Choose Key Figure])= "Sales" 
THEN [Periodic Calculation] 
ELSEIF ATTR([Choose Key Figure])= "Volume" 
THEN [Periodic Calculation] 
ELSEIF ATTR([Choose Key Figure])="profit" 
THEN [Periodic Calculation 2] 
ELSEIF ATTR([Choose Key Figure])="price per unit" 
THEN [Periodic Calculation 2] 
END 

但我得到以下錯誤: 「不能混用骨料和非集合比較或結果'IF'表達式。「

定期計算

IF [Choose Vol/NNS]="NNS" 
AND [Choose Period]=-1 
AND DATEDIFF("month",[Dates], [Choose Current Month])<2 
AND 
DATEDIFF("month",[Dates],[Choose Current Month])>0 
then [(Actuals+Planned) NNS] 
ELSEIF [Choose Vol/NNS]="Volume" 
AND [Choose Period]=-1 
AND DATEDIFF("month",[Dates], [Choose Current Month])<2 
AND 
DATEDIFF("month",[Dates],[Choose Current Month])>0 
THEN [(Actuals + Planned) Volume] 
ELSEIF [Choose Vol/NNS]="NNS" 
AND [Choose Period]=-3 
AND DATEDIFF("month",[Dates], [Choose Current Month])<4 
AND 
DATEDIFF("month",[Dates],[Choose Current Month])>0 
then [(Actuals+Planned) NNS] 
ELSEIF [Choose Vol/NNS]="Volume" 
AND [Choose Period]=-3 
AND DATEDIFF("month",[Dates], [Choose Current Month])<4 
AND 
DATEDIFF("month",[Dates],[Choose Current Month])>0 
THEN [(Actuals + Planned) Volume] 
ELSEIF [Choose Vol/NNS]="NNS" 
AND [Choose Period]=-6 
AND DATEDIFF("month",[Dates], [Choose Current Month])<7 
AND 
DATEDIFF("month",[Dates],[Choose Current Month])>0 
then [(Actuals+Planned) NNS] 
ELSEIF [Choose Vol/NNS]="Volume" 
AND  [Choose Period]=-6 
AND DATEDIFF("month",[Dates], [Choose Current Month])<7 
AND 
DATEDIFF("month",[Dates],[Choose Current Month])>0 
THEN [(Actuals + Planned) Volume] 
ELSEIF [Choose Vol/NNS]="NNS" 
AND  [Choose Period]=1 
AND DATEDIFF("month",[Dates], [Choose Current Month])<0 
AND 
DATEDIFF("month",[Dates],[Choose Current Month])>-2 
THEN [(Actuals+Planned) NNS] 
ELSEIF [Choose Vol/NNS]="Volume" 
AND  [Choose Period]=1 
AND DATEDIFF("month",[Dates], [Choose Current Month])<0 
AND 
DATEDIFF("month",[Dates],[Choose Current Month])>-2 
THEN [(Actuals + Planned) Volume] 
ELSEIF [Choose Vol/NNS]="NNS" 
AND  [Choose Period]=3 
AND DATEDIFF("month",[Dates], [Choose Current Month])<0 
AND 
DATEDIFF("month",[Dates],[Choose Current Month])>-4 
THEN [(Actuals+Planned) NNS] 
ELSEIF [Choose Vol/NNS]="Volume" 
AND  [Choose Period]=3 
AND DATEDIFF("month",[Dates], [Choose Current Month])<0 
AND 
DATEDIFF("month",[Dates],[Choose Current Month])>-4 
THEN [(Actuals + Planned) Volume] 
ELSEIF [Choose Vol/NNS]="NNS" 
AND  [Choose Period]=6 
AND DATEDIFF("month",[Dates], [Choose Current Month])<0 
AND 
DATEDIFF("month",[Dates],[Choose Current Month])>-7 
THEN [(Actuals+Planned) NNS] 
ELSEIF [Choose Vol/NNS]="Volume" 
AND  [Choose Period]=6 
AND DATEDIFF("month",[Dates], [Choose Current Month])<0 
AND 
DATEDIFF("month",[Dates],[Choose Current Month])>-7 
THEN [(Actuals + Planned) Volume] 

END

定期計算2

IF [Choose IGM$/NNSP]="NNSP" 
AND [Choose Period]=-1 
AND ATTR(DATEDIFF("month",[Dates], [Choose Current Month]))<2 
and ATTR(DATEDIFF("month",[Dates],[Choose Current Month]))>0 
THEN [(Actuals + Planned) NNSP] 
ELSEIF [Choose IGM$/NNSP]="IGM$" 
AND [Choose Period]=-1 
AND ATTR(DATEDIFF("month",[Dates], [Choose Current Month]))<2 
and ATTR(DATEDIFF("month",[Dates],[Choose Current Month]))>0 
THEN [(Actuals + Planned) IGM$] 
ELSEIF [Choose IGM$/NNSP]="NNSP" 
AND [Choose Period]=-3 
AND ATTR(DATEDIFF("month",[Dates], [Choose Current Month]))<4 
and ATTR(DATEDIFF("month",[Dates],[Choose Current Month]))>0 
THEN [(Actuals + Planned) NNSP] 
ELSEIF [Choose IGM$/NNSP]="IGM$" 
AND [Choose Period]=-3 
AND ATTR(DATEDIFF("month",[Dates], [Choose Current Month]))<4 
and ATTR(DATEDIFF("month",[Dates],[Choose Current Month]))>0 
THEN [(Actuals + Planned) IGM$] 
ELSEIF [Choose IGM$/NNSP]="NNSP" 
AND [Choose Period]=-6 
AND ATTR(DATEDIFF("month",[Dates], [Choose Current Month]))<7 
and ATTR(DATEDIFF("month",[Dates],[Choose Current Month]))>0 
THEN [(Actuals + Planned) NNSP] 
ELSEIF [Choose IGM$/NNSP]="IGM$" 
AND [Choose Period]=-6 
AND ATTR(DATEDIFF("month",[Dates], [Choose Current Month]))<7 
and ATTR(DATEDIFF("month",[Dates],[Choose Current Month]))>0 
THEN [(Actuals + Planned) IGM$] 
ELSEIF [Choose IGM$/NNSP]="NNSP" 
AND [Choose Period]=1 
AND ATTR(DATEDIFF("month",[Dates], [Choose Current Month]))<0 
and ATTR(DATEDIFF("month",[Dates],[Choose Current Month]))>-2 
THEN [(Actuals + Planned) NNSP] 
ELSEIF [Choose IGM$/NNSP]="IGM$" 
AND [Choose Period]=1 
AND ATTR(DATEDIFF("month",[Dates], [Choose Current Month]))<0 
and ATTR(DATEDIFF("month",[Dates],[Choose Current Month]))>-2 
THEN [(Actuals + Planned) IGM$] 
ELSEIF [Choose IGM$/NNSP]="NNSP" 
AND [Choose Period]=3 
AND ATTR(DATEDIFF("month",[Dates], [Choose Current Month]))<0 
and ATTR(DATEDIFF("month",[Dates],[Choose Current Month]))>-4 
THEN [(Actuals + Planned) NNSP] 
ELSEIF [Choose IGM$/NNSP]="IGM$" 
AND [Choose Period]=3 
AND ATTR(DATEDIFF("month",[Dates], [Choose Current Month]))<0 
and ATTR(DATEDIFF("month",[Dates],[Choose Current Month]))>-4 
THEN [(Actuals + Planned) IGM$] 
ELSEIF [Choose IGM$/NNSP]="NNSP" 
AND [Choose Period]=6 
AND ATTR(DATEDIFF("month",[Dates], [Choose Current Month]))<0 
and ATTR(DATEDIFF("month",[Dates],[Choose Current Month]))>-7 
THEN [(Actuals + Planned) NNSP] 
ELSEIF [Choose IGM$/NNSP]="IGM$" 
AND [Choose Period]=6 
AND ATTR(DATEDIFF("month",[Dates], [Choose Current Month]))<0 
and ATTR(DATEDIFF("month",[Dates],[Choose Current Month]))>-7 
THEN [(Actuals + Planned) IGM$] 
END 

任何人都可以如何解決這個錯誤幫助嗎?

謝謝。

回答

1

如果[選擇鍵圖]是一個參數,[週期性計算]和[週期計算2]是行級(非集合)的計算,那麼你可以:

  1. 刪除所有的來電ATTR()中的計算字段 或
  2. 除去所有到ATTR(呼叫)並調用聚合函數如SUM()上的每個參考到[週期計算]或[週期性計算2] 或
  3. 保對ATTR()的調用並在每個引用上調用諸如SUM()的聚合函數到[定期計算]或[定期計算2]

1和2之間的區別在於是否爲計算內的計算字段指定聚合函數,或者是在使用該計算字段的Tableau工作簿貨架中指定聚合函數。

在這種情況下沒有真正的理由選擇第三種方法,因爲參數一次只能有一個值,所以ATTR()調用沒有用。

+0

謝謝亞歷克斯。解決方案完美無缺。 –