如何在 SSRS 公式中使用 IN 语句

How do I use an IN statement in SSRS Formula

是否有一种简单的方法可以在 SSRS 公式中执行 IN 语句或类似的东西来进行 iff 语句比较,而无需重复 switch 16 次?

这就是我想要完成的,而不必为每个值编写语句或单独的 OR 即(Fields!FieldName.Value = "01" OR Fields!FieldName.Value = "02"...等):

=iif((Fields!FieldName.Value IN
("01","02","03","06","08","09","10","12","15","19"),"TypeA",
iff((Fields!ProdCode.Value IN ("04","07","11","13","14","16"),
"TypeB","TypeC")

试试这个:

=Switch(
Array.IndexOf(Split("01,02,03,06,08,09,10,12,15,19",","), Fields!FieldName.Value)>-1,"TypeA",
Array.IndexOf(Split("04,07,11,13,14,16",","),Fields!FieldName.Value)>-1,"TypeB",
true,"TypeC"
)

如果有帮助请告诉我。

我模拟了一个加入在 sql 中生成的 table 的示例。这比在报告中做更有效率

SELECT a,b,c,d, etc
, Lookup.FieldName, Lookup.TypeLabel
FROM Tables INNER JOIN 
(SELECT '01' AS FieldName, "TypeA" as TypeLabel
UNION ALL
SELECT '02' , "TypeA"
UNION ALL
SELECT '03' , "TypeA"
UNION ALL
SELECT '04' , "TypeB"
UNION ALL
...

SELECT '18' , "TypeC"
UNION ALL
SELECT '19' , "TypeC") LookUp 
ON Tables.FieldName = Lookup.FieldName

或者这样:

=switch( 
Instr( "," & "01,02,03,06,08,09,10,12,15,19" & ",", "," & Fields!FieldName.Value & ",") > 0  ,"TypeA",
Instr( "," & "04,07,11,13,14,16" & ",", "," & Fields!ProdCode.Value & ",") > 0  ,"TypeB",
True, "TypeC")