Dynamic field name in SSRS
I'm trying to get the value of a field, but that field name needs to be dynamic.
i.e.
=iif(Fields!Year1.Value = 1, 0, 1)
But I need a part Year1
to be returned from another dataset, so it Year1
is dynamic (maybe Year2
, Year3
etc.)
I have a field that returns data
=First(Fields!YearCount.Value, "YearColumn").
This expression by itself will return the part Year1
, Year2
etc., however I am struggling to link this with the if statement.
I tried:
=iif(Fields!(First(Fields!YearCount.Value, "YearColumn")).Value = 1, 0, 1)
eg.
source to share
The notation for a field reference in SSRS is:
=Fields!FieldName
or then
=Fields(FieldName)
So, in your case, try this:
=Fields(First(Fields!YearCount.Value, "YearColumn")).Value
because the inner function must return Year1
(or some other value), you must get an expression like:
=Fields("Year1").Value
and that should give you the value you need.
source to share