Power BI Desktop 中的数据分类Data categorization in Power BI Desktop

Power BI Desktop 中,你可以为列指定数据类别,以便让 Power BI Desktop 知道如何在可视化效果中处理其值。In Power BI Desktop, you can specify the Data Category for a column so Power BI Desktop knows how it should treat its values when in a visualization.

当 Power BI Desktop 导入数据时,它不仅会获取本身数据,还会获取表和列名称等信息(无论它是否为主关键字)。有了这些信息,Power BI Desktop 会进行某些假设,让你在创建可视化效果时可拥有较好的默认体验。When Power BI Desktop imports data, not only does it get the data itself, it also gets information such as the table and column names, whether it’s a primary key, etc. With that information, Power BI Desktop makes some assumptions about how to give you a good default experience when creating a visualization.

下面的示例说明:当 Power BI Desktop 检测到某列有数字值时,你可能想以某种方式进行聚合,由此它将会被置于值区域。Here’s an example: When Power BI Desktop detects a column has numeric values, you’ll probably want to aggregate it in some way, so it’s placed in the Values area. 或者,对于带日期时间值的列,它会假设你可能将其用作折线图上的时间层次结构轴。Or, for a column with date time values, it assumes you’ll probably use it as a time hierarchy axis on a line chart.

但是,有些情况比较具有挑战性,如地理位置。But, there are some cases that are a bit more challenging, like geography. 请思考下列来自 Excel 工作表的表:Consider the following table from an Excel worksheet:

Power BI Desktop 应该将 GeoCode 列中的代码视为国家/地区或美国州名的缩写吗?Should Power BI Desktop treat the codes in the GeoCode column as an abbreviation for a Country or a US State? 由于此类代码可能表示这两种意思中的任何一个,因此并不清楚。It’s not clear because a code like this can mean either one. 例如,AL 可以表示阿拉巴马或阿尔巴尼亚,AR 可以表示阿肯色或阿根廷,CA 可以表示加利福尼亚州或加拿大。For instance, AL can mean Alabama or Albania, AR can mean Arkansas or Argentina, or CA can mean California or Canada. 当我们在地图上绘制 GeoCode 字段时,需要加以区分。It makes a difference when we go to chart our GeoCode field on a map. Power BI Desktop 是突出显示了国家/地区的世界地图,还是突出显示了各州的美国地图呢?Should Power BI Desktop show a picture of the world with countries highlighted or a picture of the United States with states highlighted? 你可以为此类型的数据指定数据类别。You can specify a Data Category for data just like this. 数据分类进一步改进 Power BI Desktop 可用于提供最佳可视化效果的信息。Data categorization further refines the information Power BI Desktop can use to provide the best visualizations.

指定数据类别To specify a Data Category

  1. 在“报表视图”或“数据视图”中的字段列表中,选择你想要按不同的分类进行排序的字段。In Report View or Data View, in the Fields list, select the field you want to be sorted by a different categorization.
  2. 在功能区的数据工具建模选项卡上,单击数据类别:下拉列表。On the ribbon, in the Data Tools Modeling tab, click on the Data Category: drop down list. 这将显示你可以从列中选择的数据类别列表。This shows the list of possible data categories you can choose for your column. 如果某些选项不适用于列的当前数据类型,它们可能会被禁用。Some selections might be disabled if they won’t work with the current data type of your column. 例如,如果列为二进制数据类型,Power BI Desktop 将不允许你选择地理数据类别。For example, if a column is a binary data type, Power BI Desktop won’t let you choose geographic data categories.

这样就大功告成了!And that’s it! 通常累算到视觉对象的任何行为将会自动进行。Any behavior that normally accrues to a visual will now work automatically.

你可能还有兴趣了解 Power BI 移动应用的地理筛选You might also be interested in learning about geographic filtering for Power BI mobile apps.