[英]SSRS Label Formatting with expression
我目前正在处理 SSRS 报告,并希望根据值是否超过一百万来更改格式 有人可以帮我解决代码的语法吗?
=IIF(Sum(Fields!ID_Total_Spend_.Value, "DS_ClientsYear") > 1000000, £#,,.0M;('£'#,N2,'m'), £#,0,k;(‘£’#,N2,’k’))
I'm not sure exactly what you are trying to get to but here's an example I built that should get you close enough.我不确定您要达到的确切目标,但这是我构建的一个示例,应该可以让您足够接近。
I've assumed that我假设
I created a sample dataset using the following (in case you want to reproduce)我使用以下内容创建了一个示例数据集(以防您想重现)
DECLARE @t TABLE(id int, amount float)
INSERT INTO @t VALUES
(1, 1), (2,99), (3,99123), (4, 999123), (5, 1000000), (6, 12345678),
(7, -1), (8, -99), (9,-99123), (10, -999123), (11, -1000000), (12, -12345678)
SELECT * FROM @t
I then added a simple table showing然后我添加了一个简单的表格显示
ID column (for reference), the raw amount unformatted, the raw amount formatted with the "c2" standard currency formatting, the converted amount based on the amount value and finally the converted amount with a custom formatting applied. ID 列(供参考),未格式化的原始金额,使用“c2”标准货币格式格式化的原始金额,基于金额值的转换金额,最后是应用自定义格式的转换金额。
I'll only explain the final column as that's probably what you want.我只会解释最后一列,因为这可能是您想要的。
The first things I did was change the expression of the final textbox to我做的第一件事是将最终文本框的表达式更改为
=SWITCH(
ABS(Fields!amount.Value) >1000000, Fields!amount.Value / 1000000,
ABS(Fields!amount.Value) >1000, Fields!amount.Value / 1000,
True, Fields!amount.Value
)
This simply divides the amount
based on it's value.这只是根据它的价值来划分
amount
。 SWITCH
stops when it hits the first expression that returns true so there is no need to worry about amounts between certain values. SWITCH
在遇到第一个返回 true 的表达式时停止,因此无需担心某些值之间的数量。 Note I test the ABS(amount)
to the division works on both the +ive and -ive numbers in the same manner.请注意,我以相同的方式测试了除法的
ABS(amount)
对 +ive 和 -ive 数字的作用。 The final True
acts like an else
.最后的
True
就像一个else
。
You can see the output this expression gives in "raw converted amount" column.您可以在“原始转换金额”列中看到此表达式给出的输出。
In the format property of the final textbox I set the expression to在最终文本框的格式属性中,我将表达式设置为
=SWITCH(
ABS(Fields!amount.Value) > 1000000, "£#.00M;(£#.00M)",
ABS(Fields!amount.Value) > 1000, "£#.00K;(£#.00K)",
True, "£#.00;(£#.00)"
)
We are doing the same checks that we did to convert the amount but this time returning a valid format string.我们正在做与转换金额相同的检查,但这次返回一个有效的格式字符串。 In this example I used a 2 section string, the bit before the semi-colon applies to +ive number and zero.
在此示例中,我使用了 2 节字符串,分号前的位适用于 +ive 数字和零。 The second part applies to -ive numbers only.
第二部分仅适用于 -ive 数字。
The final output looks like this...最终输出看起来像这样......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.