使用 Power BI 报表和仪表板中的表(教程)Working with tables in Power BI reports and dashboards (Tutorial)

表是以逻辑序列的行和列表示的包含相关数据的网格。A table is a grid that contains related data in a logical series of rows and columns. 它还包含标头和合计行。It may also contain headers and a row for totals. 表格可以进行数量比较,可以在其中查看单个类别的多个值。Tables work well with quantitative comparisons where you are looking at many values for a single category. 例如,该表显示了类别的 5 个不同的度量值。For example, this table displays 5 different measures for Category.

何时使用表When to use a table

在以下情况下选择表是不错的选择:Tables are a great choice:

  • 查看并比较详细数据和精确值(而不是可视化表示形式)时to see and compare detailed data and exact values (instead of visual representations)
  • 以表格格式显示数据时to display data in a tabular format
  • 按类别显示数值数据时to display numerical data by categories

备注

如果表格具有过多值,请考虑将其转换为矩形图和/或使用向下钻取。If a table has too many values, consider converting it to a matrix and/or using drilldown.

先决条件Prerequisites

  • Power BI 服务或 Power BI DesktopPower BI service or Power BI Desktop
  • 零售分析示例Retail Analysis sample

创建表Create a table

我们将创建上图所示的表,以按项目类别显示销售值。We'll create the table pictured above to display sales values by item category. 若要跟着介绍一起操作,请登录 Power BI 服务,并依次选择“获取数据”>“示例”“零售分析示例”>“连接”>,再选择“转至仪表板”。To follow along, sign in to Power BI service and select Get Data > Samples > Retail Analysis Sample > Connect and choose **Go to dashboard. 创建可视化效果需要对数据集和报表拥有编辑权限。Creating a visualization requires edit permissions to the dataset and report. 幸运的是,所有 Power BI 示例都是可以编辑的。Luckily, the Power BI samples are all editable. 如果报表已与你共享,则无法在报表中创建可视化效果。If a report has been shared with you, you won't be able to create visualizations in reports.

  1. 在左侧导航窗格中,选择“工作区 > 我的工作区”。From the left navpane, select Workspaces >My workspace.
  2. 选择“数据集”选项卡,然后向下滚动到你刚才添加的“零售分析示例”数据集。Select the Datasets tab, and scroll down to the Retail Analysis Sample dataset you just added. 选择“创建报表”图标。Select the Create report icon.

  3. 在报表编辑器中,选择“项” > “类别”。In the report editor, select Item > Category. Power BI 会自动创建一个表,该表列出所有类别。Power BI automatically creates a table that lists all the categories.

  4. 选择“销售 > 平均单价和“销售 > 去年销售额”以及“销售 > 本年度销售额”,并选择所有 3 个选项(值、目标和状态)。Select Sales > Average Unit Price and Sales > Last Year Sales and Sales > This Year Sales and choose all 3 options (Value, Goal, Status).
  5. 在可视化效果窗格中,找到“”一列并拖放值,直到图表列的顺序与该页的第一个图像相匹配。In the Visualizations pane, locate the Values well and drag-and-drop the values until the order of your chart columns matches the first image on this page. “值”列应如下所示。Your Values well should look like this.

  6. 通过选择大头针图标将该表固定到仪表板Pin the table to the dashboard by selecting the pin icon

设置表格格式Format the table

有多种设置表格格式的方法,这里只介绍其中几种。There are many many ways to format a table and we'll only cover a few of them here. 若要了解其他格式设置选项,请打开“格式设置”窗格(滚动油漆刷图标 )并进行浏览。A great way to learn about the other formatting options is to open the Formatting pane (paint roller icon ) and explore.

  • 尝试设置表格中网格的格式。Try formatting the table grid. 此处我们已添加蓝色垂直网格,为行添加了空间,并稍微增加了边框和文本的大小。Here we've added a blue vertical grid, added space to the rows, increased the outline and text size a bit.

  • 对于列标题,我们更改了背景色、添加了边框,并增加了字体大小。For the column headers we changed the background color, added an outline, and increased the font size.

  • 进行了一些其他格式设置后,最终表格如下。And after some additional formatting, here is our final table. 由于格式设置选项较多,最好的了解方法是打开一个空白表格,打开“格式设置”窗格 ,然后开始浏览。Since there are so many formatting options, the best way to learn is to start with a plain table, open the Formatting pane , and start exploring.

条件格式设置Conditional formatting

一种类型的格式设置称为条件格式设置,可应用于 Power BI 服务或桌面的“可视化效果”窗格的“值”框的字段中。One type of formatting is referred to as conditional formatting and is applied to fields in the Values well of the Visualizations pane in Power BI service or Desktop.

通过表的条件格式设置,可以根据单元格值指定自定义单元格背景色和字体颜色,包括使用渐变色。With conditional formatting for tables, you can specify customized cell background colors and font colors based on cell values, including using gradient colors.

  1. 在 Powr BI Desktop 服务或桌面的“可视化效果”窗格中,在要设置其格式的“值”框中,选择值旁边的向下箭头(或右键单击该字段)。In the Visualizations pane in Power BI service or Desktop, select the down-arrow beside the value in the Values well that you want to format (or right-click the field). 只能管理“字段”格的“值”区域中字段的条件格式。You can only manage conditional formatting for fields in the Values area of the Fields well.

  2. 选择“背景色阶”。Select Background color scales. 在随即显示的对话框中,可以配置颜色,以及最小和最大值。In the dialog that appears, you can configure the color, as well as the Minimum and Maximum values. 如果选择“散射”框,还可以配置一个可选的“居中”值。If you select the Diverging box, you can configure an optional Center value as well.

    我们将某些自定义格式设置应用于“平均单价”值。Let's apply some custom formatting to our Average Unit Price values. 选择“散射”,添加一些颜色,然后选择“确定”。Select Diverging, add some colors, and choose OK.

  3. 将新字段添加到具有正值和负值的表中。Add a new field to the table that has both positive and negative values. 选择“销售额”>“总销售差额”。Select Sales > Total Sales Variance.

  4. 添加数据条条件格式设置,方法是选择“总销售差额”旁边的向下箭头,然后选择“条件格式设置”>“数据条”。Add data bar conditional formatting by selecting the down-arrow beside Total Sales Variance and choosing Conditional formatting > Data bars.

  5. 在出现的对话框中,依次设置“正值条形图”、“负值条形图”的颜色,在“仅显示数据条”旁边放置一个选中标记,并进行所需的任何其他更改。In the dialog that appears, set colors for Positive bar, Negative bar, place a checkmark next to Show bar only, and make any other changes you'd like.

    当选择“确定”时,数据条会替换表格中的数字值,使其更易于扫描。When you select OK, data bars replace the numerical values in the table making it easier to scan.

  6. 若要从可视化效果中删除条件格式,只需再次右键单击该字段,并选择删除条件格式即可。To remove conditional formatting from a visualization, just right-click the field again, and select Remove Conditional Formatting.

提示

还可以在“格式设置”窗格(滚动油漆刷图标)中进行条件格式设置。Conditional formatting is also available from the Formatting pane (paintroller icon). 选择要设置其格式的值,然后将“色阶”或“数据条”设置为“打开”以应用默认设置,或者,若要自定义设置,请选择“高级控件”。Select the value to format and then set Color scales or Data bars to On to apply the default settings or, to customize the settings, select Advanced controls.

调整表的列宽度的大小Adjust the column width of a table

有时 Power BI 会截断仪报表中或仪表板上的列标题。Sometimes Power BI will truncate a column heading in a report and on a dashboard. 若要显示整个列名称,将鼠标悬停在标题右侧的空白处以显示双箭头,然后选择并拖动它。To show the entire column name, hover over the space to the right of the heading to reveal the double arrows, select and drag.

更多问题?More questions? 尝试参与 Power BI 社区Try the Power BI Community