我试图在Tableau中执行以下操作。
I am trying to do the following in Tableau.
如果所选关键指标是销售额或销量(非汇总字段),则调用计算1否则计算2。
If the chosen key figure is sales or volume (non-aggregate fields) then call calculation1 else calculation 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'表达式。
But I am getting the following error: "Cannot mix aggregate and non-aggregate comparisons or results in 'IF' expressions."
定期计算
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有人可以帮助解决该错误吗?
Can anyone help with how to work around this error?
谢谢。
推荐答案如果[选择关键指标]是参数,并且[定期计算]和[定期计算2]为行级(非总计)计算,那么您可以:
If [Choose Key Figure] is a parameter, and [Periodic Calculation] and [Periodic Calculation 2] are row level (non aggregate) calculations, then you can either:
1和2之间的区别是是在计算中还是在使用Tableau的工作簿书架中为计算字段指定聚合函数
The difference between 1 and 2 is whether to specify the aggregation function for your calculated field inside the calculation or in the Tableau workbook shelves where it is used.
在这种情况下,没有真正的理由选择第三种方法,因为参数一次只能有一个值,因此ATTR()调用没有用。
No real reason to choose the third approach in this case since parameters can only have a single value at a time, so the ATTR() call is not useful.
更多推荐
解决Tableau中IF结果的聚合和非聚合混合错误
发布评论