简体   繁体   English

Power BI 报表生成器指标公式

[英]Power BI Report Builder Indicator Formula

I am adding in an indicator to a PBI Report Builder Report.我正在向 PBI 报告生成器报告中添加一个指标。 The indicator is based off multiple fields from the dataset so I need to use a formula, to create the three up/down/side arrows.该指标基于数据集中的多个字段,因此我需要使用一个公式来创建三个向上/向下/侧向箭头。 Previously in Crystal Reports this could be implemented using a series of IF statements as follows.以前在 Crystal Reports 中,这可以使用如下的一系列 IF 语句来实现。 The below example is what is required for the down arrow.以下示例是向下箭头所需的内容。 (the other 2 arrows also have multiple calculations) (另外2个箭头也有多重计算)

        IF (({spScorecard_SLView;1.CATEGORY_ID} = 4) OR 
       ({spScorecard_SLView;1.CATEGORY_ID} = 25)) THEN 
        IF ({spScorecard_SLView;1.PM_3MM_NC_CNT}-{spScorecard_SLView;1.3MM_NC_CNT}) < 
        0 THEN 'Down Arrow'

        ELSE IF (({spScorecard_SLView;1.CATEGORY_ID} = 21) 
        OR({spScorecard_SLView;1.CATEGORY_ID} = 26) OR 
        ({spScorecard_SLView;1.CATEGORY_ID} = 41)) THEN
        IF ({spScorecard_SLView;1.CM_TOTAL_CNT}> 0) AND 
        (({spScorecard_SLView;1.PM_3MM_TOTAL_CNT} = 0) OR 
        ({spScorecard_SLView;1.3MM_TOTAL_CNT} = 0)) AND 
        ({spScorecard_SLView;1.3MM_NC_CNT} > 0) AND 
        (((({spScorecard_SLView;1.3MM_TOTAL_CNT} - {spScorecard_SLView;1.3MM_NC_CNT}) 
        / {spScorecard_SLView;1.3MM_TOTAL_CNT}) * 100) >= 0.00) THEN 'Down Arrow' //

        ELSE IF ((((({spScorecard_SLView;1.3MM_TOTAL_CNT} - 
        {spScorecard_SLView;1.3MM_NC_CNT}) / {spScorecard_SLView;1.3MM_TOTAL_CNT}) * 
        100) -((({spScorecard_SLView;1.PM_3MM_TOTAL_CNT} - 
        {spScorecard_SLView;1.PM_3MM_NC_CNT}) / 
        {spScorecard_SLView;1.PM_3MM_TOTAL_CNT}) * 100))/100) < 0.00 THEN 
        'Down Arrow'

I am stuck as to how to do something similar in PBI Report builder.我被困在如何在 PBI 报告生成器中做类似的事情。 Should I create a formula in the Value field under Value and States, and then delete any arrow settings under the Indicator States?我是否应该在值和状态下的值字段中创建一个公式,然后删除指标状态下的任何箭头设置? Can you create a formula using 'Down Arrow' etc in an IIf statement?您可以在 IIf 语句中使用“向下箭头”等创建公式吗? I can only get indicator data returned when selecting 1 field under Value, but I need multiple fields & conditions.在值下选择 1 个字段时,我只能获取返回的指标数据,但我需要多个字段和条件。

在此处输入图片说明

SSRS Reports are similar to PBI Report builder so if there are any examples using it that may be of help. SSRS 报告类似于 PBI 报告生成器,因此如果有任何使用它的示例可能会有所帮助。 I am connecting to a SQL Server stored proc to pull back the data.我正在连接到 SQL Server 存储过程以拉回数据。

Thanks Blowers感谢鼓风机

I would approach it like this...我会像这样接近它......

Set a formula in the Indicator Value so that you return a number that corresponds to the arrow you want to show (eg return 1, 2 or 3)在指标值中设置一个公式,以便返回与要显示的箭头相对应的数字(例如,返回 1、2 或 3)

You can use whatever format you feel comfotable with but I would suggest using the SWITCH() function rather than nested IIF s.你可以使用任何你觉得舒服的格式,但我建议使用SWITCH()函数而不是嵌套的IIF s。

For example this checks two fields and returns one of three values, (this is just a random example to illustrate the point)例如,这会检查两个字段并返回三个值之一,(这只是一个随机示例来说明这一点)

=SWITCH(
SUM(Fields!Amount.Value) >5000 AND Fields!Year.Value >2019, 1
, SUM(Fields!Amount.Value) >10000 AND Fields!Year.Value <2019, 2
, True, 3
)

Switch takes pairs of expressions and return values. Switch 接受成对的表达式和返回值。 It returns the value when it hits the first expression that evaluates to True .它在遇到第一个计算结果为True表达式时返回该值。 So this reads...所以这读...

  • If the aggregated Amount is greater than 5000 and the Year >2019 then return 1如果合计Amount大于 5000 且Year >2019,则返回 1
  • If the aggregated Amount is greater than 10000 and the Year <2019 then return 12如果合计Amount大于 10000 且Year <2019,则返回 12
  • Else return 3否则返回 3

The final 'True', as it will always return true acts like an ELSE最后的“真”,因为它总是像一个ELSE一样返回true

Anyway, this will return a value of either 1, 2 or 3无论如何,这将返回 1、2 或 3 的值

Then in the Indicator Properties, just set the range for each indicator to 1, 2 or 3 like this然后在指标属性中,像这样将每个指标的范围设置为 1、2 或 3

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM