解决Tableau中IF结果的聚合和非聚合混合错误

编程入门 行业动态 更新时间:2024-10-23 05:43:50
本文介绍了解决Tableau中IF结果的聚合和非聚合混合错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图在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:

  • 删除您对ATTR()的所有调用计算字段或
  • 删除对ATTR()的所有调用,并在对[Periodic Calculation]或[Periodic Calculation 2]的每个引用上调用聚合函数,例如SUM() 或
  • 保留对ATTR()的调用,并在每次引用[Periodic Calculation]或[Periodic Calculation 2]时调用诸如SUM()之类的聚合函数
  • 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结果的聚合和非聚合混合错误

    本文发布于:2023-11-22 15:08:31,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1617910.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:错误   Tableau

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!