首页 > 解决方案 > 如何在 Tableau 中为当年和上一年的销售额总和创建计算字段?

问题描述

如何在表格中为当年和上一年的销售额总和创建计算字段?

标签: tableau-api

解决方案


您可以使用 if 语句将过滤条件有效地嵌入计算中,对于不满足您的条件的数据行,默认情况下评估为 null。Sum() 之类的聚合函数会默默地忽略空值。

current_year_sales

If Year([Sale Date]) = Year(Today()) then [Sale Amount] end

previous_year_sales

If Year([Sale Date]) = Year(DateAdd(‘year’, -1, [Sale Date])) then [Sale Amount] end

推荐阅读