在 Power BI Desktop 中使用相对日期切片器和筛选器Use a relative date slicer and filter in Power BI Desktop

借助相对日期切片器或筛选器,可以向数据模型中的任意日期列应用时间筛选器。With the relative date slicer or relative date filter, you can apply time-based filters to any date column in your data model. 例如,可以使用相对日期切片器,仅显示过去 30 天(或月、日历月等)的销售数据。For example, you can use the relative date slicer to show only sales data that's happened within the last thirty days (or month, or calendar months, and so on). 刷新数据时,相对时间段会自动应用相应的相对日期约束。And when you refresh the data, the relative time period automatically applies the appropriate relative date constraint.

使用相对日期范围切片器Using the relative date range slicer

相对日期切片器的使用方法与其他任何切片器的使用方法一样。You can use the relative date slicer just like any other slicer. 只需为报表创建切片器视觉对象,再选择日期值作为“字段”值即可。Simply create a slicer visual for your report, and then select a date value for the Field value. 在下图中,选择的是“订购日期”字段。In the following image, the OrderDate field is selected.

选择“相对日期切片器”右上角的脱字号。此时,系统会显示菜单。Select the carat in the upper-right corner of the relative date slicer and a menu appears.

若要使用相对日期切片器,请选择“相对”。For the relative date slicer, select Relative.

然后,可以选择设置。You then can select the settings. 对于“相对日期切片器”中的第一个下拉列表,可以选择下列选项:For the first drop-down in the relative date slicer, you can select from the following choices:

  • 最后一个Last
  • 下一步Next
  • This

这些选项如下图所示。These selections are shown in the following image.

通过“相对日期切片器”中的“下一个(中间)”设置,可以键入一个数字来定义相对日期范围。The next (middle) setting in the relative date slicer allows you to type in a number, to define the relative date range.

通过第三个设置,可以选择日期度量,并能选择下列选项:The third setting allows you to select the date measurement, and you can select from the following choices:

  • Days
  • Weeks
  • 周(日历)Weeks (Calendar)
  • Months
  • 月(日历)Months (Calendar)
  • Years
  • 年(日历)Years (Calendar)

这些选项如下图所示。These selections are shown in the following image.

如果在此列表中选择“月”,并在中间设置中输入 2。If you select Months from that list, and input 2 in the middle setting. 将发生以下情况:如果今天是 7 月 20 日,那么切片器约束的视觉对象会显示前两个月的数据,即从 5 月 20 日一直到 7 月 20 日(今天的日期)。The following would happen: if today is July 20th, the data included in visuals constrained by the slicer would show data for the previous two months, starting on May 20th and going through July 20th (today's date).

相比之下,如果选择“月(日历)”,约束的视觉对象则会显示从 5 月 1 日一直到 6 月 30 日(过去两个整日历月)的数据。In comparison, if you selected Months (Calendar), the visuals constrained would show data from May 1st through June 30th (the last two complete calendar months).

使用相对日期范围筛选器Using the relative date range filter

还可以为报表页或整个报表创建相对日期范围筛选器。You can also create a relative date range filter for your report page, or your entire report. 为此,只需将日期字段拖到“字段”窗格中的“页面级筛选器”或“报表级筛选器”区域即可,如下图所示。To do so, simply drag a date field into the Page level filters or the Report level filters areas in the Field pane, as shown in the following image.

就位后,可以修改相对日期范围,具体操作与自定义“相对日期切片器”类似。Once there, you can modify the relative date range in similar fashion to how the relative date slicer is customized. 在“筛选器类型”下拉列表中选择“相对日期筛选”。Select Relative date filtering from the Filter Type drop down.

选择“相对日期筛选”后,便可以修改三个部分,包括中间的数字框,就像切片器一样。Once Relative date filtering is selected, you see three sections to modify, including a middle numeric box, just like the slicer.

在报表中使用相对日期约束就是这么简单。And that's all there is to using these relative date constraints in your reports.

限制和注意事项Limitations and considerations

目前,使用相对日期范围切片器和筛选器时,需要遵循以下限制和注意事项。The following limitations and considerations currently apply to the relative date range slicer and filter.

  • Power BI 中的数据模型不包括时区信息。Data models in Power BI do not include time zone information. 模型可以存储时间,但并不指明所在时区。The models can store times, but there's no indication of the time zone they're in.
  • 切片器和筛选器始终以 UTC 时间为依据。因此,如果在报表中配置筛选器,并将其发送给位于不同时区的同事,看到的数据仍相同。The slicer and filter are always based on the time in UTC, so if you configure a filter in a report and send it to a colleague in a different time zone, you'll both see the same data. 不过,如果你不在 UTC 时区,数据可能会发生与预期不同的时间偏移。However, if you aren't in the UTC time zone you might see data for a different time offset than you expect.
  • 可以使用“查询编辑器”,将在本地时区捕获的数据转换为 UTC。Data captured in a local time zone can be converted to UTC using the Query Editor.