Darren G
Darren G

Reputation: 233

How can I get From a SSRS DataSet Row the Value Where Condition is True

I have a DataSet called Reporting that include TagName, Value and DateTime.

Now my question: In my SSRS Report I have a TextBox where I want the Value of a TagName.

For Example: I have TagName called: "TT101" with the Value 21.

So my TextBox should show 21.

I have tried with this expression:

=IIf(Fields!TagName.Value = "TT101" , Fields!Value.Value ,0)

So I expected the output this expression to be 21 but it was 0 because it's always false or Null and I can't find out why?

Upvotes: 1

Views: 4629

Answers (2)

AnkUser
AnkUser

Reputation: 5541

enter image description here So as described, You had data coming from Dataset something like below. As you already have attribute (column) which gives you value why do you need any expression for it.

In SSRs just use Table and assign Field to a column it will automtatically populate N number of rows (For ex.100 rows if your Dataset returns 100 rows) Here is the link for Tablix in SSRS https://learn.microsoft.com/en-us/sql/reporting-services/report-design/tables-report-builder-and-ssrs?view=sql-server-2017

As per your comment, you need max only where TagName is TT101. Let's do something like below.

Create a new Column let's call it "Value for Tag TT101" Now for this column set Value with condition as

IIf(Fields!TagName.Value = "TT101" , Fields!Value.Value ,0)

What this will do, will set Value for TT101 or 0 if different Tag Name.

Now you can have expression for Textbox as below

=Max(Fields!newColumValue.Value, "myDataSetName")

This shall work for you.

Upvotes: 1

Strawberryshrub
Strawberryshrub

Reputation: 3399

If you really just want what you descriped you need to add a Sum() to your textbox expression. Like this. All the other aggregate functions will also work, for example Max, Min, First, etc.

=Sum(IIF(Fields!TagName.Value = "TT101" , Fields!Value.Value ,0))

In a textbox you always access the whole dataset, this is the reasion why you have to aggregate it with Sum(). If you have more rows in your datasets, which meets the condition you will get a summation. If you are sure, that you have just one row which meets this condition you will get your 21.

Another way to do the same without a textbox would be a tablix. Add the whole dataset in the tablix, and then go to the tablix properties > filter and add your filter ("TT101"). This way you wont get a summation when you have more rows which meets the filter condition, you just get every row listed.

Upvotes: 0

Related Questions