Excel Dax 简明教程

Excel DAX - Editing a Calculated Field

您可以编辑计算字段以修改它。但是,在编辑计算字段之前,您应该知道它存储在哪里。意思是在哪个表中存储了计算字段。隐式计算字段和显式计算字段都是如此。一个计算字段只能与数据模型中的一个表关联。

Finding Calculated Fields

若要找到数据模型中的计算字段,请执行以下操作:

  1. 在 Power Pivot 窗口的 Ribbon 上单击高级选项卡。

  2. 单击显示隐式计算字段。

finding calculated fields
  1. Click the Diagram View.

click diagram view

正如您在上述屏幕截图中所看到的,显示隐式计算字段在 Ribbon 上被高亮显示。如果其未被高亮显示,请再次单击它。

您还可以观察到,有四个复选框 - 列、计算字段、层次结构和 KPI。默认情况下,所有四个都被选中。

  1. 取消选中框 - 列、层次结构和 KPI。

这将只保留选中计算字段框。

calculated fields box checked

如上图所示,只有结果表有显示的字段。其他两个表为空白。这表明只有结果表有计算字段。您还可以观察到,隐式计算字段显示一个图标,而显式计算字段 - 奖牌数没有该图标。

Viewing Calculated Fields in the Table

您可以按照如下步骤在表中查看计算字段:

  1. Click the calculated field.

  2. 右键单击并在下拉列表中选择转到。

viewing calculated fields in table

该表将出现在数据视图中。

data view

如上图所示,计算字段显示在表的计算区域中。

Changing a Calculated Field in the Table

您可以改变表中计算字段使用的公式。

  1. Click the calculated field in the table in data view of the Data Model.

  2. Select the formula in the formula bar – to the right side of :=.

The formula will get highlighted.

formula highlighted
  1. Type the new formula.

  2. Press Enter.

You will learn more about the DAX formulas in the subsequent chapters.

Renaming a Calculated Field in the Data Model

You can change the name of a calculated field in the Data Table either in Data View or Diagram View.

Renaming a Calculated Field in the Data View

  1. Click the calculated field in the table in data view of the Data Model.

  2. Select the calculated field name in the formula bar – to the left side of :=.

The calculated field name will get highlighted.

field name highlighted
  1. Type the new name for the calculated field.

  2. Press Enter.

You will learn more about the DAX Syntax in the subsequent chapters.

Renaming a Calculated Field in the Diagram View

  1. Right-click the calculated field name in the table in the diagram view.

  2. Click Rename in the dropdown list.

renaming calculated field in diagram view

The name will get into editing mode. Type the new name for the calculated field.

Viewing Calculated Fields in the Excel Window

You can view the calculated fields in the Excel window as follows −

  1. 单击功能区上的 POWERPIVOT 选项卡。

  2. Click Calculated Fields in the Calculations group.

  3. 在下拉列表中单击“管理计算字段”。

viewing calculated fields in excel window

Manage Calculated Fields dialog box appears. The names of the explicit calculated fields in the Data Model appear in the dialog box.

manage calculated fields dialog box

Changing a Calculated Field in the Manage Calculated Fields

You can change a calculated field in the Manage Calculated Fields dialog box.

  1. Click the Medal Count.

  2. Click the Edit button.

changing calculated field in manage calculated fields

计算字段对话框出现。

  1. Select the formula to the right of = in the formula box.

calculated field dialog box appear
  1. Type the new Formula.

  2. Click OK.

  3. Click Close in the Manage Calculated Fields dialog box.

Renaming a Calculated Field in the Manage Calculated Fields

您可以在“管理计算字段”对话框中重命名计算字段。

  1. Click the Medal Count.

  2. Click the Edit button.

计算字段对话框出现。

  1. 在计算字段名称框中选择名称。

renaming calculated field in manage calculated fields
  1. Type the new name for the calculated field.

  2. Click OK.

  3. Click Close in the Manage Calculated Fields dialog box.

Moving a Calculated Field in the Data Model

您可以在创建它的表的计算区域内移动计算字段。但是,它无法移动到其他表。

  1. Right-click the calculated field.

  2. Click Cut.

  3. 将指针移动到同一表的计算区域中的其他位置。

  4. Click Paste.

Note - 计算字段在表的计算区域中的位置并不重要,因为计算字段的 DAX 公式中的数据引用是按列名称进行的,并且是明确说明的。