在 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.

了解 Power BI 如何計算總和Understanding how Power BI calculates totals

在開始了解如何使用矩陣視覺效果之前,務必先了解 Power BI 如何計算資料表和矩陣中的總和與小計值。Before jumping into how to use the Matrix visual, it's important to understand how Power BI calculates total and subtotal values in tables and matrices. 針對總和與小計資料列,量值會根據基礎資料的所有資料列進行評估,而不是僅僅加總可見或顯示資料列中的值。For total and subtotal rows, the measure is evaluated over all rows in the underlying data – it is not just a simple addition of the values in the visible or displayed rows. 這表示在總和資料列中,可能會得到與您預期不同的值。This mean you can end up with different values in the total row than you might expect.

看看下列矩陣視覺效果。Take a look at the following Matrix visuals.

在此範例中,矩陣視覺效果最右邊的每個資料列都會顯示每位銷售人員/日期組合的 Amount (數量)。In this example, each row in the Matrix visual farthest to the right is showing the Amount for each salesperson/date combination. 不過,因為由於銷售人員能在多個日期上顯示,數字可能會出現一次以上。However, since a salesperson shows up against multiple dates, the numbers can appear more than once. 因此,基礎資料的正確總和並不等於可見值的單純加總。Thus the accurate total from the underlying data, and a simple addition of the visible values, do not equate. 當加總的值屬於一對多關係中的「單一」端時,這是的常見模式。This is a common pattern when the value you’re summing is on the ‘one’ side of a one-to-many relationship.

查看總和與小計時,請記住這些值是來自基礎資料,而不是來自可見值。When looking at total and subtotals, remember that those values are based on the underlying data, and not solely based on the visible values.

使用矩陣視覺效果的向下切入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. 在下圖中,已用滑鼠右鍵按一下 [Computers] 並選取 [向下切入]。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. 在下圖中,我們以滑鼠右鍵按一下 [Deluxe],然後選取 [向下切入]。In the following image, we right-click on Deluxe and select Drill Down.

選取 [向下切入] 時,會顯示 [Deluxe] 之資料行階層的下一個層級,在本例中為 [色彩]。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. 請注意,[Computers] 類別已將其子類別 ([Computers Accessories]、[Desktops]、[Laptops]、[Monitors] 等) 稍微縮排,以提供更精簡的視覺效果。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:

後續步驟Next steps

您可能也會對下列文章感興趣:You might also be interested in the following articles: