Power BI 中的切片器Slicers in Power BI

备注

可以在 Power BI Desktop 和 Power BI 服务中创建并查看这些视觉对象。These visuals can be created and viewed in both Power BI Desktop and the Power BI service. 本文中的步骤和图示来自 Power BI Desktop。The steps and illustrations in this article are from Power BI Desktop.

你希望报表读者能够查看总体销售指标,但同时突出显示各个地区经理和不同时间范围的业绩表现。You want your report readers to be able to look at overall sales metrics, but also highlight performance for individual District Managers and different time frames. 可以创建单独的报表或比较图表,也可以使用切片器。You could create separate reports or comparative charts, or you could use slicers. 切片器是另一种筛选方法,用于限制在报表的其他可视化效果中显示的部分数据集。A slicer is an alternate way of filtering that narrows the portion of the dataset shown in the other visualizations in a report.

本教程通过免费的零售分析示例,演示如何创建、格式化以及使用列表及日期范围切片器。This tutorial uses the free Retail Analysis Sample to walk you through creating, formatting, and using list and date range slicers. 通过有趣的新方法使用切片器并进行格式化。Have fun discovering ways to format and use slicers.

slicer

何时使用切片器When to use a slicer

在要完成以下操作时,切片器非常有用:Slicers are a great choice when you want to:

  • 在报表画布上显示常用或重要的筛选器,用以简化访问。Display commonly-used or important filters on the report canvas for easier access.
  • 更轻松地查看当前筛选的状态,而无需打开下拉列表。Make it easier to see the current filtered state without having to open a drop-down list.
  • 按数据表中不需要的和隐藏的列进行筛选。Filter by columns that are unneeded and hidden in the data tables.
  • 通过将切片器放置在重要的视觉对象旁边来创建更多报表。Create more focused reports by putting slicers next to important visuals.

Power BI 切片器存在以下限制:Power BI slicers have the following limitations:

  • 切片器不支持输入字段。Slicers do not support input fields.
  • 切片器不支持明细。Drilldown is not supported for slicers.

创建切片器Create slicers

创建新的切片器以按地区经理筛选数据Create a new slicer to filter data by District Manager

本教程使用零售分析示例 PBIX 文件This tutorial uses the Retail Analysis sample PBIX file.

  1. 在菜单栏的左上方,选择“文件” > “打开” From the upper left section of the menubar, select File > Open

  2. 查找零售分析示例 PBIX 文件的副本Find your copy of the Retail Analysis sample PBIX file

  3. 在报表视图中打开零售分析示例 PBIX 文件 报表视图屏幕截图图标Open the Retail Analysis sample PBIX file in report view Screenshot of the report view icon..

  4. 选择Select 黄色选项卡的屏幕截图。 ,以添加新报表页。to add a new page.

  5. 在“概述”页上,画布上不选中任何内容,选择“可视化效果”窗格中的“切片器”图标切片器图标来创建新的切片器 。On the Overview page, with nothing selected on the canvas, select the Slicer icon slicer icon in the Visualizations pane to create a new slicer.

  6. 在选择新切片器后,从“字段”窗格中选择“地区” > “地区经理”来填充切片器 。With the new slicer selected, from the Fields pane, select District > DM to populate the slicer. 新切片器是一个在名称前有选择框的列表。The new slicer is a list with selection boxes before the names.

    新切片器

  7. 调整大小并将切片器和其他元素拖至画布,以便为切片器腾出空间。Resize and drag the slicer and other elements on the canvas to make room for the slicer. 请注意,如果切片器的大小调整得过小,切片器项将被截断。Note that the slicer items are cut off if you resize the slicer too small.

  8. 选择切片器上的名称,并注意对页面上其他可视化效果的影响。Select names on the slicer and note the effects on the other visualizations on the page. 再次选中名称以取消选择,并按住 Ctrl 键选择多个名称。Select names again to deselect them, and hold down the Ctrl key to select more than one name. 选择所有名称与不选择任何名称的效果相同。Selecting all names has the same effect as selecting none.

  9. 或者,选择滚动油漆刷图标以设置切片器的格式。Alternately, select the paint roller icon to format your slicer. 此处介绍了太多选项,因此,尝试并创建适合你的切片器。There are simply too many options to describe them all here - so experiment and create a slicer that works for you. 在下面的示例中,第一个切片器使用水平方向,并对项使用彩色背景。In the examples below, the first slicer uses a horizontal orientation and uses colored backgrounds for the items. 第二个切片器已保持垂直,转为为文本着色以获得更标准的外观。The second slicer has been kept vertical and instead colors the text for a more standard look.

    新切片器

提示

默认情况下,列表切片器项按升序的方式进行排序。List slicer items are sorted in ascending order by default. 若要按反向降序顺序进行排序,请选择切片器右上角的省略号 (... ),然后选择“降序排序” 。To reverse the sort order to descending, select the ellipsis (...) in the top right corner of the slicer and choose Sort descending.

创建新的切片器以按日期范围筛选数据To create a new slicer to filter data by date range

  1. 画布上不选中任何内容,下拉“字段”窗格中的“商店” ,并将“OpenDate” 拖至“可视化效果”窗格中的“值” 中,以创建新的可视化效果。With nothing selected on the canvas, drop down Store in the Fields pane, and drag OpenDate to the Values well in the Visualizations pane to create a new visualization.

  2. 选择新的可视化效果后,选择“切片器” 图标,将新的可视化效果转换为切片器。With the new visualization selected, select the Slicer icon to convert the new visualization to a slicer. 此切片器是填充有日期范围的滑块控件。This slicer is a slider control with the date range populated.

    新范围切片器

  3. 调整大小并将切片器和其他元素拖至画布,以便为切片器腾出空间。Resize and drag the slicer and other elements on the canvas to make room for the slicer. 请注意,滑块大小根据切片器大小进行调整,但如果切片器大小调整得过小,它将消失且日期会被截断。Note that the slider resizes with the slicer size, but it disappears and the dates are cut off if you resize the slicer too small.

  4. 在滑块中选择不同的日期范围,或选择“日期”字段以键入值,或弹出日历以便更精确地进行选择。Select different date ranges with the slider, or select a date field to type in a value or pop up a calendar for more precise selection. 请注意对页面上其他可视化效果的影响。Note the effects on the other visualizations on the page.

    备注

    默认情况下,数值和日期/时间数据类型会生成范围滑块切片器。Numeric and date/time data types produce range slider slicers by default. 从 2018 年 2 月 Power BI 更新开始,整数数据类型范围滑块现对齐到整数值,而不是显示小数位。Starting with the February 2018 Power BI update, whole number data type range sliders now snap to whole number values rather than showing decimal places.

  5. 若要更改切片器类型,请在选择切片器后,将鼠标悬停在切片器的右上方区域,下拉显示的脱字号列表,然后选择其他选项之一,如“列表” 或“之前” 。To change the slicer type, with the slicer selected, hover over the upper-right area of the slicer, drop down the carat that appears, and choose one of the other options, such as List or Before. 请注意切片器的外观和选择选项如何变化。Note how the slicer appearance and selection options change.

    新范围切片器

若要深入了解如何创建日期和数值范围切片器,请观看以下视频或参阅在 Power BI Desktop 中使用数值范围切片器For more about creating date and numeric range slicers, watch the following video and see Use the numeric range slicer in Power BI Desktop.

备注

此视频使用较旧版本的 Power BI Desktop。This video uses an older version of Power BI Desktop.

控制受切片器影响的页面视觉对象Control which page visuals are affected by slicers

默认情况下,报表页上的切片器会影响该页上的所有其他可视化效果,而且还会相互影响。By default, slicers on report pages affect all the other visualizations on that page, including each other. 在刚创建的列表和日期滑块中选择值时,请注意对其他可视化效果的影响。As you choose values in the list and date sliders you just created, note the effects on the other visualizations. 筛选后的数据是这两个切片器中所选值的交集。The filtered data is an intersection of the values selected in both slicers.

可以使用“视觉对象交互” 来排除某些页面的可视觉化效果,以免受到其他可视化效果的影响。You can use Visual interactions to exclude some page visualizations from being affected by others. 在“概述” 页上,“按财月和地区经理排列的总销售额方差”图表显示针对地区经理的按月总体比较数据,你希望此数据在任何时候都保持可见。On the Overview page, the "Total Sales Variance by FiscalMonth and District Manager" chart shows overall comparative data for District Managers by Month, which you want to keep visible at all times. 可以使用“视觉对象交互” 来阻止切片器选择筛选此图表。You can use Visual interactions to keep slicer selections from filtering this chart.

  1. 在“地区每月销售”页上选择地区经理切片器 :With the District Manager slicer on the District Monthly Sales page selected:

    • 在 Power BI Desktop 中,选择“可视化工具” 下的“格式” 菜单并选择“编辑交互” 。In Power BI Desktop, select the Format menu under Visual Tools and select Edit interactions.

    页面上所有其他视觉对象上方随即显示筛选器控件筛选器控件Filter controls filter controls appear above all the other visuals on the page. 最初,所有“筛选器” 图标都将被选中。Initially, all the Filter icons are selected.

  2. 选择“按财月和地区经理排列的总销售额方差” 图表上的“无” 图标,以停止切片器对其进行筛选。Select the None icon above the Total Sales Variance by FiscalMonth and District Manager chart to make the slicer stop filtering it.

  3. 选择“月”切片器 ,然后再次选择“按财月和地区经理排列的总销售额方差” 图表上的“无” 图标,以停止此切片器对其进行筛选。Select the Month slicer, and again select the None icon above the Total Sales Variance by FiscalMonth and District Manager chart to make this slicer stop filtering it. 现在,当你在切片器中选择名称和日期范围时,“按财月和地区经理排列的总销售额方差”图表将保持不变。Now, as you select names and date ranges in the slicers, the Total Sales Variance by FiscalMonth and District Manager chart is unchanged.

有关编辑交互的详细信息,请参阅 Power BI 报表中的视觉对象交互See Visual interactions in a Power BI report for more information about editing interactions.

同步切片器并在其他页面上使用Sync and use slicers on other pages

自 Power BI 2018 年 2 月更新起,可同步切片器并在报表的任意页面上使用。Starting with the February 2018 Power BI update, you can sync a slicer and use it on any or all pages in a report.

在当前报表中,“地区每月销售”页也包含“地区经理”切片器,但如果我们还希望在“概述”页上包含该切片器,该怎么办 ?In the current report, the District Monthly Sales page also has a District Manager slicer, but what if we also wanted that slicer on the Overview page? “新商店”页也包含切片器,但仅提供“商店名称”信息 。The New Stores page also has a slice, but it only provides Store Name information. 使用“同步切片器”窗格,可以在这些页面上同步“地区经理”切片器,以便任何页上的切片器选择会影响所有三个页面上的可视化效果 。With the Sync slicer pane we can sync the District Manager slicer to these pages, so that slicer selections on any page affect visualizations on all three pages.

  1. 在“视图”菜单上,选择 Power BI Desktop 中的“同步切片器” 。On the View menu, select Sync slicers in Power BI Desktop.

    同步切片器

  2. “同步切片器”窗格显示在“筛选器”和“可视化效果”窗格之间 。The Sync Slicers pane appears between the Filters and Visualizations pane.

    同步切片器

  3. 在“地区每月销售”页上,选择“地区经理”切片器 。On the District Monthly Sales page, select the District Manager slicer.

    同步切片器

  4. 在“同步” 列中,选择“新商店” 页和“概述” 页,以将“地区每月销售” 切片器同步到这些页面上。In the Sync column, select the New Stores page and the Overview page to sync the District Monthly Sales slicer to those pages.

  5. 在“可见”列中,选择“新商店”页和“概述”页 。In the Visible column, select the New Stores page and Overview page. “同步切片器” 窗格现在应如下图所示:Your Sync slicers pane should now look like the image below:

    同步切片器

  6. 观察同步切片器并使其在其他页上可见的影响。Observe the effects of syncing the slicer and making it visible on the other pages. 在“地区每月销售” 页上,“地区经理” 切片器现显示与“概述” 页上的切片器相同的选择。On the District Monthly Sales page, the District Manager slicer now shows the same selections as the one on the Overview page. 在“新商店” 页上,选择“地区经理” 切片器会影响可在“商店名称” 切片器中使用的选择。On the New Stores page, the selections in the District Manager slicer affect the selections that are available in the Store Name slicer.

    提示

    尽管切片器最初以与原始页面相同大小和相同位置的方式出现在同步页面上,但你可以在不同页面上独立移动、调整大小和格式化同步切片器。Although the slicer initially appears on the synced pages at the same size and position as on the original page, you can move, resize, and format synced slicers on the various pages independently.

备注

如果将切片器同步到一个页面,但不让它在该页上可见,那么在其他页面上所做的切片器选择仍然会筛选该页上的数据。If you sync a slicer to a page but do not make it visible on that page, slicer selections made on the other pages still filter the data on the page.

格式化切片器Format slicers

可用的不同格式化选项具体取决于切片器类型。Different formatting options are available depending on the slicer type. 通过使用“水平” 方向、“响应式” 布局,和“项” 着色,可以生成按钮或磁贴,而不是标准列表项,并使切片器项调整大小以适应不同的屏幕大小和布局。By using Horizontal orientation, Responsive layout, and Item coloring, you can produce buttons or tiles rather than standard list items, and make slicer items resize to fit different screen sizes and layouts.

  1. 在任何页面上选择“区域经理” 切片器后,在“可视化效果” 窗格中选择“格式” 图标格式图标以显示格式设置控件。With the District Manager slicer selected on any page, in the Visualizations pane, select the Format icon format icon to display the formatting controls.

    格式设置

  2. 选择每个类别旁边的下拉列表箭头,显示和编辑选项。Select the drop-down arrows next to each category to display and edit the options.

常规选项General options

  1. 选择“边框颜色” 中的红色,并将“边框粗细” 更改为“2”。Select red under Outline color and change Outline weight to "2". 启用时,将设置标头和项目外虚线框或实线框的颜色/粗细。This sets the color and thickness of the header and item outlines or underlines, when enabled.

  2. 在“方向” 下,“垂直” 是默认设置。Under Orientation, Vertical is the default. 选择“水平” 可以生成带水平排列磁贴或按钮的切片器,并滚动箭头访问切片器中不适合的项。Select Horizontal to produce a slicer with horizontally arranged tiles or buttons, and scroll arrows to access items that do not fit in the slicer.

    水平

  3. 启用“响应式” 布局切片器,根据屏幕和切片器大小更改切片器项的大小和排列方式。Turn on Responsive layout to change the size and arrangement of slicer items according to viewscreen and slicer size. 对于列表切片器,响应式布局仅适用于水平方向,可防止项在小屏幕上截断。For list slicers, responsive layout is only available in horizontal orientation, and prevents items from being cut off on small screens. 对于范围滑块切片器,响应式格式设置更改滑块样式,并且可以更灵活地调整大小。For range slider slicers, responsive formatting changes the style of the slider and provides more flexible resizing. 这两种类型的切片器都变成了非常小的筛选器图标。Both types of slicers become filter icons at very small sizes.

    响应式

    备注

    更改响应式布局后,可能会覆盖所设置的特定标题和项格式。Responsive layout changes may override specific heading and item formatting that you set.

  4. 在“X 位置” 、“Y 位置” 、“宽度” 和“高度” 中使用数值精度设置切片器位置和大小,或者直接在画布上移动切片器或调整其大小。Set the slicer position and size with numeric precision under X Position, Y Position, Width, and Height, or move and resize the slicer directly on the canvas. 尝试不同的项大小和布局,并注意响应式格式设置如何相应地更改。Experiment with different item sizes and arrangements, and note how the responsive formatting changes accordingly.

    水平按钮

若要深入了解水平方向和响应式布局,请参阅在 Power BI 中创建可调整大小的响应式切片器See Create a responsive slicer you can resize in Power BI for more about horizontal orientation and responsive layout.

选择控件选项(仅列表切片器)Selection controls options (list slicers only)

  1. 默认关闭 “显示全选” 。Show Select All is Off by default. 将其打开 ,将“选择所有项” 添加到切片器,使其在切换时可选择或取消选择所有项。Turn it to On to add a Select All item to the slicer that selects or deselects all items when toggled. 在选择所有项后,单击或点击一个项以取消选择,允许“is-not”类型筛选器。When all items are selected, clicking or tapping one item deselects it, allowing an "is-not"-type filter.

    全选

  2. 默认启用 “单项选择” 。Single Select is On by default. 单击或点击每个项即将其选中,按住 Ctrl 键并同时单击或点击多个项可选择多个项。Clicking or tapping each item selects it, and holding down the Ctrl key while clicking or tapping selects multiple items. 关闭 “单项选择” 后,无需按 Ctrl 即可选择多个项。Turn Single Select to Off to allow selecting multiple items without holding down the Ctrl key. 再次单击或点击每个项即取消选择。Clicking or tapping each item again deselects it.

标题选项Title options

“标题” 默认开启 ,它可在切片器顶部显示数据字段名称。The Title is On by default, showing the data field name at the top of the slicer.

  1. 设置标题文本格式:将字体颜色 设为红色、文本大小 为 14 磅、居中对齐 和字体系列 为 Arial Black。Format the title text to make the Font color red, Text size 14 pt, center Alignment and Font family Arial Black.

项选项(仅列表切片器)Item options (list slicers only)

  1. 设置项文本和背景的格式:字体颜色 设为黑色、背景 为浅红色、文本大小为 为 10 pt、字体系列 为 Arial。Format item text and background to make the Font color black, Background light red, Text size 10 pt, and Font family Arial.

  2. 在“边框” 中,选择“框架” ,在每个项周围添加带有在“常规” 选项下设置的大小和颜色的边框线。Under Outline, choose Frame to draw a border around each item with the size and color you set under General options.

    格式设置

    提示

    • 设置为“方向”>“水平” 时,取消选择的项显示已选文本和背景颜色,而所选项使用系统默认设置,通常是黑色背景和白色文本。With Orientation > Horizontal, deselected items show the chosen text and background colors, while selected items use the system default, usually black background with white text.
    • 设置为“方向”>“垂直” 时,项始终显示设置的颜色,选择项时选择框始终为黑色。With Orientation > Vertical, items always show the set colors, and selection boxes are always black when selected.

日期/数值输入和滑块选项(仅范围滑块切片器)Date/numeric inputs and Slider options (range slider slicers only)

  • “日期/数值输入”选项与列表切片器的“项” 选项相同,但没有任何“边框” 或下框线。Date/numeric input options are the same as the Item options for list slicers, except there is no Outline or underline.
  • 滑块选项允许你设置范围滑块的颜色,或关闭 滑块,仅保留数值输入。Slider options allow you to set the color of the range slider, or turn the slider to Off, leaving only the numeric inputs.

其他格式设置选项Other formatting options

其他格式设置选项默认关闭。The other formatting options are off by default. 当启用 时:When turned On:

  • 背景: 将背景颜色添加到整个切片器并设置其透明度。Background: Adds a background color to the overall slicer and sets its transparency.
  • 锁定纵横比: 重新调整大小后,切片器的形状保持不变。Lock aspect: Retains the shape of the slicer if it is resized.
  • 边框: 在切片器周围添加 1 像素的边框并设置其颜色。Border: Adds a 1-pixel border around the slicer and sets its color. (此切片器边框是单独的,不受常规边框设置影响。)(This slicer border is separate from and unaffected by the General Outline settings.)

后续步骤Next steps

Power BI 中的可视化效果类型Visualization types in Power BI

Power BI 中的表Tables in Power BI