Tableau 简明教程

Tableau - Date Calculations

日期是大多数数据分析场景中广泛使用的一个关键字段。因此,Tableau 提供了许多涉及到日期的内置函数。你可以进行简单的日期操作,例如添加或减去日期中的天数。你还可以创建涉及到日期的复杂表达式。

Dates are one of the key fields which is extensively used in most of the data analysis scenarios. Hence, Tableau provides a large number of inbuilt functions involving dates. You can carry out simple date manipulations such as adding or subtracting days from a date. You can also create complex expressions involving dates.

以下是创建计算字段并在其中使用日期函数的步骤。

Following are the steps to create a calculation field and use date functions in it.

Create Calculated Field

连接到样例超级商店时,转到分析菜单并单击“创建计算字段”,如下面屏幕截图所示。

While connected to Sample superstore, go to the Analysis menu and click ‘Create Calculated Field’, as shown in the following screenshot.

Create calculation

Calculation Editor

上述步骤将打开一个计算编辑器,其中列出了 Tableau 中可用的所有函数。你可以更改下拉值并仅查看与日期相关的函数。

The above step opens a calculation editor, which lists all the functions available in Tableau. You can change the dropdown value and see only the functions related to Date.

date calc 1

Create a Formula

现在,找出销售量以及自 2009 年 3 月 21 日以来的销售日期差异(以月为单位)。为此,创建如下面的屏幕截图所示的公式。

Now, find out the sales volume along with the difference in the date of sales in months from 21st March 2009. For this, create the formula as shown in the following screenshot.

date calc 2

Using the Calculated Field

现在要查看已创建字段的操作,你可以将其拖放到行搁板中并将销售字段拖放到列搁板中。同样将发货日期与月份一起拖放。下图显示了销售值。

Now to see the created field in action, you can drag it to the Rows shelf and drag the Sales field to the Columns shelf. Also drag the ship Date with months. The following screenshot shows the Sales values.

date calc 3