在 Power BI Desktop 中使用“矩阵”视觉对象Use the Matrix visual in Power BI Desktop

借助“矩阵”视觉对象,可以在 Power BI Desktop 报表中创建矩阵视觉对象(有时亦称为“表”),并能使用其他视觉对象交叉突出显示矩阵内的元素。With the Matrix visual, you can create matrix visuals (sometimes also referred to as tables) in Power BI Desktop reports, and cross-highlight elements within the matrix with other visuals. 此外,还可以选择行、列和各个单元格进行交叉突出显示。In addition, you can select rows, columns, and even individual cells and cross-highlight. 最后,为了更好地利用布局空间,矩阵视觉对象支持阶梯布局。Lastly, to make better use of layout space, the matrix visual supports a stepped layout.

矩阵有许多相关功能,我们将在本文的下面各部分中逐一介绍它们。There are many features associated with the matrix, and we'll go through them in the following sections of this article.

备注

自 2017 年 7 月发布的 Power BI Desktop 起,矩阵和表视觉对象可以反映已应用的“报表主题”中的样式(包括颜色)。Beginning with the July 2017 release of Power BI Desktop, matrix and table visuals reflect styling (including colors) from the applied Report Theme. 这些颜色可能与对矩阵视觉对象的预期不符,可以在“报表主题”配置中进行更改。These may not be the colors you expect for your matrix visual, which you can change in your Report Theme configuration. 有关主题的详细信息,请参阅在 Power BI Desktop 中使用报表主题See Use Report Themes in Power BI Desktop for more information about themes.

结合使用向下钻取功能和矩阵视觉对象Using drill-down with the Matrix visual

借助“矩阵”视觉对象,可以执行之前无法实现的各种有意思的向下钻取活动。With the Matrix visual, you can do all sorts of interesting drill-down activities that weren't available before. 这包括向下钻取行、列、单独分区和单元格。This includes the ability to drill-down using rows, columns, and even into individual sections and cells. 让我们来看看每种向下钻取活动的工作原理。Let's take a look at how each of these work.

向下钻取行标题Drill-down on row headers

在“可视化效果”窗格中,如果你向“字段”的“”部分添加多个字段,可以为矩阵视觉对象的行启用向下钻取功能。In the Visualizations pane, when you add multiple fields to the Rows section of the Fields well, you enable drill-down on the rows of the matrix visual. 这类似于创建层次结构,以便于你可以向下钻取(然后备份)层次结构,并分析每个级别的数据。This is similar to creating a hierarchy, which then allows you to drill-down (and then back up) through that hierarchy, and analyze the data at each level.

在下图中,“ ”部分包含“ 类别 ”和“ 子类别 ”,形成了我们可以向下钻取的行分组(或层次结构)。In the following image, the Rows section contains Category and SubCategory, creating a grouping (or hierarchy) in the rows that we can drill through.

如果视觉对象在“ ”部分中形成了分组,那么视觉对象本身会在其左上角显示“ 钻取 ”和“ 扩展 ”图标。When the visual has grouping created in the Rows section, the visual itself displays the drill and expand icons in the top-left corner of the visual.

选择这些按钮可以向下钻取(或备份)层次结构,类似于其他视觉对象中的钻取和扩展行为。Similar to the drill and expand behavior in other visuals, selecting those buttons lets us drill-down (or back up) through the hierarchy. 在此示例中,我们可以从“ 类别 ”向下钻取到“ 子类别 ”,如下图所示,其中我们选择了向下钻取一个级别图标(草耙图标)。In this case we can drill down from Category to SubCategory, as shown in the following image, where the drill-down one level icon (the pitchfork) has been selected.

除了使用这些图标,还可以右键单击任意行标题,然后从显示的菜单中进行选择来向下钻取。In addition to using those icons, you can right-click on any of those row headers, and drill down by selecting from the menu that appears.

请注意,显示的菜单中有多个选项,分别用于执行不同的操作:Notice there are a few options from the menu that appears, which generates different results:

选择“ 向下钻取 ”扩展的是 行级别的矩阵,其他所有行标题 除外 ,只会扩展右键单击的行标题。Selecting Drill Down expands the matrix for that row level, excluding all other row headings except the row header that was right-clicked. 在下图中,我们右键单击“ 计算机 ”,然后选择了“向下钻取”。In the following image, Computers was right-clicked, and Drill Down was selected. 请注意,其他顶层行不会再出现在矩阵中。Notice that other top-level rows no longer appear in the matrix. 这是一项十分有用的功能,当我们介绍“交叉突出显示”部分时,你会发现这项功能特别棒。This is a useful feature, and becomes especially cool when we get to the cross-highlighting section.

我们可以单击“向上钻取”图标,返回到上一顶层视图。We can click the Drill up icon to get back to the previous top-level view. 如果我们选择右键单击菜单中的“显示下一级别”,系统会按字母顺序列出所有下一级项(在此示例中,为“ 子类别 ”字段),不含更高级别的层次结构分类。If we then select Show Next Level from the right-click menu, we get an alphabetical listing of all the next-level items (in this case, the SubCategory field), without the higher-level hierarchy categorization.

单击左上角的“向上钻取”图标让矩阵显示所有顶层类别,然后再次右键单击并选择“扩展至下一级别”,我们将看到以下内容:When we click on the Drill up icon in the upper-left corner to have the matrix show all top-level categories, then right-click again and select Expand to next level, we see the following:

还可以使用“包括”和“排除”菜单项,在矩阵中保留(或删除)右键单击的行(和所有子类别)。You can also use the Include and Exclude menu items to keep (or remove, respectively) the right-clicked row (and any subcategories) from the matrix.

向下钻取列标题Drill-down on column headers

还可以向下钻取,类似于向下钻取行。Similar to the ability to drill-down on Rows, you can also drill-down on Columns. 在下图中,你会发现,“”字段中也有两个字段,形成了类似于我们在本文前面使用的行层次结构。In the following image, you can see that there are two fields in the Columns field well, creating a hierarchy similar to what we used for the rows earlier in this article. ”字段中包含“ 类别 ”和“ 颜色 ”。In the Columns field well, we have Class and Color.

在矩阵视觉对象中,当我们右键单击某列时,可以看到向下钻取选项。In the Matrix visual, when we right-click a column, we see the option to drill-down. 在下图中,我们右键单击“ 奢华版 ”,然后选择“ 向下钻取 ”。In the following image, we right-click on Deluxe and select Drill Down.

选择“ 向下钻取 ”后,系统会显示“ 奢华版 ”列层次结构的下一级项(在此示例中,为“ 颜色 ”)。When Drill Down is selected, the next level of the column hierarchy for Deluxe is displayed, which in this case is Color.

其余的右键单击菜单项对列和行的工作方式均相同(请参阅上一部分“向下钻取行标题”)。The rest of the right-click menu items work on Columns in the same way they do for rows (see the previous section, Drill-down on row headers). 可以对列选择“显示下一级别”、“扩展至下一级别”、“包括”或“排除”,就像对行选择这些选项一样。You can Show Next Level, Expand to next level, and Include or Exclude your columns just as you can with rows.

备注

矩阵视觉对象左上角的向下钻取和向上钻取图标仅对行有效。The icons drill-down and drill-up icons in the upper left of the matrix visual only apply to rows. 必须使用右键单击菜单,才能向下钻取列。In order to drill-down on columns, you must use the right-click menu.

使用矩阵视觉对象实现阶梯布局Stepped layout with matrix visuals

矩阵视觉对象自动缩进层次结构中每个父级下的子类别,这就是所谓的“阶梯布局”。The Matrix visual automatically indents subcategories in a hierarchy beneath each parent, which is called a stepped layout.

版矩阵视觉对象中,子类别显示在完全不同的列中,占用视觉对象更多空间。In the original version of the matrix visual, subcategories were shown in an entirely different column, taking up much more space in the visual. 下图展示了旧版矩阵视觉对象中的表;请注意,子类别位于完全不同的列中。The following image shows the table in original matrix visual; notice the subcategories in a completely separate column.

下图展示了采用阶梯布局的“矩阵”视觉对象的实际效果。In the following image, you see a Matrix visual, with stepped layout in action. 请注意,类别“ 计算机 ”将其子类别(“计算机附件”、“台式机”、“笔记本电脑”、“显示器”等)略微缩进,让视觉对象变得更简洁紧凑。Notice the category Computers has its subcategories (Computers Accessories, Desktops, Laptops, Monitors, and so on) slightly indented, providing a cleaner and much more condensed visual.

可以轻松调整“阶梯布局”设置。You can easily adjust the stepped layout settings. 选择“矩阵”视觉对象后,在“可视化效果”窗格的“格式”部分(滚动油漆刷图标)中,展开“行标题”部分。With the Matrix visual selected, in the Format section (the paint roller icon) of the Visualizations pane, expand the Row headers section. 下面有两个选项:“阶梯布局”开关(用于启用或禁用阶梯布局)和“阶梯布局缩进”(用于指定缩进量,以像素为单位)。In there are two options: the Stepped layout toggle (which turns it off or on), and the Stepped layout indentation (specifies the indentation amount, in pixels).

如果禁用“阶梯布局”,子类别会显示在另一列中,而不是在父类别下缩进。If you turn off Stepped layout, the subcategories are shown in another column rather than indented beneath the parent category.

矩阵视觉对象小计Subtotals with matrix visuals

可以在矩阵视觉对象中,打开或关闭行和列的小计。You can turn subtotals on or off in matrix visuals, for both rows and columns. 在下图中,可以看到行小计已设置为“打开”。In the following image, you can see that the row subtotals are set to on.

在“可视化效果”窗格的“格式”部分中,展开“小计”卡,并将“行小计”滑块移动至“关闭”。In the Format section of the Visualizations pane, expand the Subtotals card and turn the Row subtotals slider to Off. 执行此操作后,将不显示小计。When you do so, the subtotals are not shown.

相同的操作过程适用于列小计。The same process applies for column subtotals.

使用矩阵视觉对象进行交叉突出显示Cross-highlighting with matrix visuals

借助“矩阵”视觉对象,可以选择矩阵中的任意元素,作为交叉突出显示的依据。With the Matrix visual, any elements in the matrix can be selected as the basis for cross-highlighting. 在“矩阵”中选择一列即可突出显示它,报表页上的其他任何视觉对象也会予以反映。Select a column in a Matrix and that column is highlighted, as are any other visuals on the report page. 这一直是其他视觉对象的常见功能,即可以选择数据点,现在“矩阵”视觉对象也加入进来了。This has been a common feature of other visuals and the selection of a data point, and now the Matrix visual can participate.

此外,还可以在按住 CTRL 的同时单击鼠标进行交叉突出显示。In addition, using CTRL+Click also works for cross-highlighting. 例如,在下图中,我们选择了“矩阵”视觉对象中的一组子类别。For example, in the following image a collection of subcategories were selected from the Matrix visual. 请注意,视觉对象中未选择的项为灰显,报表页上的其他视觉对象也会反映“矩阵”视觉对象中选择的项。Notice how items that weren't selected from the visual are grayed out, and how the other visuals on the page reflect the selections made in the Matrix visual.

矩阵视觉对象的底纹和字体颜色Shading and font colors with matrix visuals

借助“矩阵”视觉对象,可以将条件格式(颜色和底纹)应用于矩阵中的单元格背景,还能将条件格式应用于文本和值本身。With the Matrix visual, you can apply conditional formatting (colors and shading) to the background of cells within the matrix, and you can apply conditional formatting to the text and values themselves.

要应用条件格式,可以在选中矩阵视觉对象后执行以下任一操作:To apply conditional formatting, you can do either of the following when a matrix visual is selected:

  • 在“字段”窗格中,右键单击“字段”,然后在菜单中选择“条件格式”。In the Fields pane, right-click the Field, and select Conditional formatting from the menu.

  • 或者,在“格式”窗格中,展开“条件格式”卡,然后,将“背景色阶”或“字体色阶”的滑块移动至“打开”。Or, in the Format pane, expand the Conditional formatting card and for either Background color scales or Font color scales, turn the slider to On. 将上述任一滑块移动至“打开”会显示“高级控件”的链接,转到该链接可以对颜色格式的颜色和值进行自定义。Turning either on displays a link for Advanced controls, which allows you to customize the colors and values for the color formatting.

两种方法都能达到相同的结果。Either approach achieves the same result. 选择“高级控件”会显示以下对话框,可在其中进行调整:Selecting Advanced controls displays the following dialog, which lets you make adjustments:

限制和注意事项Limitations and considerations

这一版“矩阵”视觉对象有一些限制和注意事项。In this release of the Matrix visual, there are a few limitations and considerations to keep in mind.

  • 只能使用右键单击菜单钻取列,并且视觉对象当前没有任何迹象表明可钻取行组或列组Drill on columns can only be done by using the right-click menu, and there's currently no indication on the visual that you can drill into row or column groups
  • 只能一次性扩展一个级别中的所有项,不能一次扩展一个类别You can only expand all items in a level at once, rather than expanding one category at a time
  • 右键单击列标题时可能会看到“参阅记录”,但这并不是操作选项See Records may appear on a menu when right-clicking a column headers, but it is not operational
  • 暂无“总计 ”行There currently is no Grand total row
  • 禁用阶梯布局中的“小计”行不会产生任何影响Turning off the subtotal row in stepped layout doesn't have any effect
  • 如果内部组的文本比外部组更短,那么列标题可能会被截断Column headers may be truncated if inner groups have shorter text than the outer group
  • 更改阶梯布局缩进量不得更改最外侧行组的缩进量Changing the stepped layout indentation shouldn't indent the outermost row group's indent

我们非常希望听取你的意见。We're always eager to hear your thoughts. 目前,我们正在开展有关这一版“矩阵”视觉对象的调查。请花几分钟的时间参与此项调查吧。We're currently conducting a survey on this Matrix visual, so if you have a few minutes, please take the survey.