Power BI – 基于 RLS 的条件格式化

huangapple go评论71阅读模式
英文:

Power BI - Conditional Formatting based on RLS

问题

基于 RLS,是否可以创建一个针对特定数值/度量的条件格式化?

例如,拥有成本数值/度量,如果我将用户放入一个名为“绿色”的角色中,那么这些用户将以绿色显示负数值。如果我将用户放入一个名为“红色”的角色中,那么这些用户将以红色显示负数值。

因为现在我正在创建两份报告,仅因为这个功能,如果有一种方法可以在一个报告中处理所有内容,那将是非常好的。

我尝试过搜索,但没有找到太多信息,如果有人能帮助我实现这个目标,我将非常感激。

谢谢!

英文:

Is it possible based on RLS, create a conditional formatting in a certain value/measure?

For example, having the cost value/measure, and if I put the users in a role called Green, for example, these users will see the negative values ​​in green. If I put the users in a role called Red, these users will see negative values ​​in red.

Because right now I'm creating two reports just because of this feature, if there was any way to have everything in one report it would be great.

I tried searching but didn't find much information, if someone can help me in achieving this, I would appreciate it very much.

Thank you!

答案1

得分: 2

在这种情况下甚至不需要使用RLS。这将是杀鸡用牛刀,而且还需要在生产环境中进行支持。

最好的方法是将一个未连接的表加载到数据模型中,包含所有用户的电子邮件及其“配置”(使表在数据模型中不可见)。

然后,您可以像david建议的那样使用条件格式设置

  1. 在数据集中创建一个辅助度量,用于获取用户的颜色。
UserColor = 
VAR LoggedInEmail = USERPRINCIPALNAME()
RETURN
    CALCULATE(
        SELECTEDVALUE(user[color]),
        user[email] = LoggedInEmail
    )
  1. 使用链接中描述的度量与条件格式选项。

附注:在某些情况下(例如本地Power BI报表服务器),您需要使用USERNAME()函数而不是USERPRINCIPALNAME()函数。

英文:

It is not even necessary to use RLS in this case. It would be overkill and would require you to support it in production as well.

Best idea would be to load an unconnected table with all user emails and their "configuration" (make the table invisible inside the datamodel) to your datamodel.

Power BI – 基于 RLS 的条件格式化

Then, you can use conditional formatting as suggested by david like this:

  1. create a helper measure in your dataset, that retrieves the color of the user.
UserColor = 
VAR LoggedInEmail = USERPRINCIPALNAME()
RETURN
    CALCULATE(
        SELECTEDVALUE(user[color]),
        user[email] = LoggedInEmail
    )
  1. use the measure as described in the link with conditional formatting option

PS: in certain situations (e.g. local power bi report server) you need to use USERNAME() function instead

答案2

得分: 1

当然。

> 如果您有带有颜色名称或十六进制值数据的字段或度量,您可以使用条件格式设置自动将这些颜色应用于列的背景或字体颜色。您还可以使用自定义逻辑来将颜色应用于字体或背景。

条件格式设置 - 按颜色数值设置

因此,您可以拥有一个带有“颜色名称或十六进制值”的未连接表,然后使用行级安全性(RLS)来控制哪些用户可以看到哪些颜色行。

英文:

Sure.

> If you have a field or measure with color name or hex value data, you can use conditional formatting to automatically apply those colors to a column's background or font color. You can also use custom logic to apply colors to the font or background.

Conditional Formatting - Color by Color Values

So have an unconnected table with the "color names or hex values", and then use RLS to control which users can see which color rows.

huangapple
  • 本文由 发表于 2023年7月4日 23:59:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76614290.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定