Luis
Luis

Reputation: 6001

Microsoft Reports Adding Two Column Values

Is it possible to add two column values say I have 3 columns:

Item 1                |    Item 2                |  Total

=Fields!Item1.Value   |   =Fields!Item1.Value    |   ???

What I want to avoid (for maintainability reasons) is doing something like this:

=Fields!Item1.Value + Fields!Item2.Value

I am rather looking for something like

Column1Value + Column2Value

Thanks Guys!!!!

Upvotes: 5

Views: 6275

Answers (4)

Scott Willeke
Scott Willeke

Reputation: 9345

You could also do this by adding a calculated field in your dataset. So add your two source fields, lets call them Item1 and Item2, normally - with their Source set to the name of the field in the data source. Then add a calculated field, letss call it Total to the report dataset by setting the Field's Expression to =Fields!Item1.Value + Fields!Item2.Value. Then anywhere in your report you can access the calculated value by using =Fields!Total.Value.

This way you get your calculation without modifying the underlying datasource, it is more maintainable (the calculation in one place) it simplifies referencing the calculation throughout the report.

Upvotes: 4

D.S.
D.S.

Reputation: 1413

Sounds like what you would like to do is reference the value of the report object (the textbox) rather than the column from the query. You can do this by using ReportItems!.

When you drag out the column from the dataset, it may name the text box after the column, if the column name can vary you will want to assign a static value to the text box in which the value will appear.

So, in the initial example you gave, you will have textboxes by the names of Item1, Item2, and Total. Thus, in the appropriate Total textbox you will want:

=ReportItems!Item1.Value + ReportItems!Item2.Value

or if you named the textboxes Red and Blue it would be:

=ReportItems!Red.Value + ReportItems!Blue.Value

alt text alt text

A list of available ReportItems will pop up when you hit '!' after ReportItems.

Upvotes: 5

Ta01
Ta01

Reputation: 31630

If you use a matrix, the behavior you seek is inbuilt.

Upvotes: 2

Jason Down
Jason Down

Reputation: 22191

I would just do the addition in the query and return it as a calculated field.

e.g.

SELECT field1, field2, field1 + field2 AS total;

I don't see the maintainability problem with this. If you need to keep the query separate from everything else, consider stored procedures or some sort of factory to generate the query.

Upvotes: 3

Related Questions