Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Field Name in SSRS

I'm trying to Retrieve a value of a field, but that name of the field needs to be dynamic.

i.e.

=iif(Fields!Year1.Value = 1, 0, 1)

But I need the Year1 part to be returned from another dataset, so the Year1 is dynamic (could be Year2, Year3 etc....)

I have a field that returns the data

 =First(Fields!YearCount.Value, "YearColumn").

This expression in itself will return the Year1, Year2 etc.. part, however I am struggling to concatenate this with the if statement.

I have tried:

=iif(Fields!(First(Fields!YearCount.Value, "YearColumn")).Value = 1, 0, 1) 

for example.

like image 462
jjm Avatar asked Jan 14 '23 05:01

jjm


1 Answers

The notation to reference a field in SSRS is either:

=Fields!FieldName

or then

=Fields(FieldName)

So in your case, try this:

=Fields(First(Fields!YearCount.Value, "YearColumn")).Value 

because the inner function should return Year1 (or another value), you should get an expression like:

=Fields("Year1").Value 

and that should give you your value you need.

like image 100
marc_s Avatar answered Jan 21 '23 20:01

marc_s