Power BI Desktop 中基于表达式的标题Expression-based titles in Power BI Desktop

可为 Power BI 视觉对象创建动态的自定义标题。You can create dynamic, customized titles for your Power BI visuals. 通过基于字段、变量或其他编程元素来创建数据分析表达式 (DAX),可以根据需要自动调整视觉对象的标题。By creating Data Analysis Expressions (DAX) based on fields, variables, or other programmatic elements, your visuals' titles can automatically adjust as needed. 这些更改基于筛选器、所选内容或其他用户交互和配置。These changes are based on filters, selections, or other user interactions and configurations.

Power BI Desktop 条件格式选项的屏幕截图

创建动态标题(有时称为“基于表达式的标题” )非常简单。Creating dynamic titles, sometimes called expression-based titles, is straightforward.

为标题创建字段Create a field for your title

创建基于表达式的标题的第一步是在模型中创建一个用于标题的字段。The first step in creating an expression-based title is to create a field in your model to use for the title.

有各种创造性的方法可以让视觉对象标题反映出你想要表达的内容。There are all sorts of creative ways to have your visual title reflect what you want it to say, or what you want to express. 我们来看看几个示例。Let's take a look at a couple examples.

可创建一个表达式,该表达式会根据视觉对象接收到的用于产品品牌名的筛选器上下文进行更改。You can create an expression that changes based on the filter context that the visual receives for the product's brand name. 下图显示了此类字段的 DAX 公式。The following image shows the DAX formula for such a field.

DAX 公式的屏幕截图

另一个示例是使用根据用户的语言或区域性进行更改的动态标题。Another example is using a dynamic title that changes based on the user's language or culture. 可使用 USERCULTURE() 函数在 DAX 度量值中创建特定于语言的标题。You can create language-specific titles in a DAX measure by using the USERCULTURE() function. 此函数根据用户的操作系统或浏览器设置返回用户的区域性代码。This function returns the culture code for the user, based on their operating system or browser settings. 可使用以下 DAX switch 语句来选择正确的转换后的值。You can use the following DAX switch statement to select the correct translated value.

  "de-DE", “Umsatz nach Produkt”,
  "fr-FR", “Ventes par produit”,
  “Sales by product”

或者,可从包含所有转换的查找表中检索字符串。Or you can retrieve the string from a lookup table that contains all the translations. 将该表放在模型中。You place that table in your model.

这些只是有助于在 Power BI Desktop 中为视觉对象创建基于表达式的动态标题的一部分示例。These are just a couple of examples you can use to create dynamic, expression-based titles for your visuals in Power BI Desktop. 你可以采用任何你想象得到的方式来处理标题,只要适合你的模型。What you can do with your titles are limited only by your imagination, and your model.

为标题选择字段Select your field for your title

在为模型中创建的字段创建 DAX 表达式后,需要将其应用于视觉对象的标题。After you've created the DAX expression for the field you create in your model, you need to apply it to your visual's title.

若要选择该字段并应用,请转到“可视化效果”窗格 。To select the field and apply it, go to the Visualizations pane. 在“格式”区域中,选择“标题”以显示可用于视觉对象的标题选项 。In the Format area, select Title to show the title options for the visual.

右键单击“标题文本”,这将显示一个上下文菜单,可在其中选择“fx条件格式” 。When you right-click Title text, a context menu appears that allows you to select fxConditional formatting. 选择该菜单项后,会出现“标题文本”对话框 。When you select that menu item, a Title text dialog box appears.


在该窗口中,可选择所创建的用于标题的字段。From that window, you can select the field that you created to use for your title.

限制和注意事项Limitations and considerations

当前基于表达式的视觉对象标题的实现存在一些限制:There are a few limitations to the current implementation of expression-based titles for visuals:

  • Python 视觉对象、R 视觉对象或“关键影响因素”视觉对象目前不支持基于表达式的格式设置。Expression-based formatting isn’t currently supported on Python visuals, R visuals, or the Key Influencers visual.
  • 为标题创建的字段必须是字符串数据类型。The field you create for the title must be a string data type. 目前不支持会返回数字或日期/时间(或任何其他数据类型)的度量值。Measures that return numbers or date/time (or any other data type) aren't currently supported.
  • 将视觉对象固定到仪表板时,不会保留基于表达式的标题。Expression based titles aren't carried over when you pin a visual to a dashboard.

后续步骤Next steps

本文介绍了如何创建 DAX 表达式,将视觉对象的标题转换为可在用户与报表交互时发生更改的动态字段。This article described how to create DAX expressions that turn the titles of your visuals into dynamic fields that can change as users interact with your reports. 以下文章可能也会对你有所帮助。You might find the following articles useful as well.