Microsoft reports adding two column values

Is it possible to add two column values, for example, I have 3 columns:

Item 1 | Item 2 | Total =Fields!Item1.Value | =Fields!Item1.Value | ??? 

What I want to avoid (for convenience) does the following:

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

I'm rather looking for something like

 Column1Value + Column2Value 

Thanks guys!!!!

+4
source share
4 answers

You can also do this by adding a calculated field to your dataset. Thus, add two source fields, allow them to access the items Item1 and Item2 normally, and their source sets the field name in the data source. Then add the calculated field, let's call it Total in the report dataset by setting the field expression to = fields! Item1.Value + Fields! Item2.Value. Then, anywhere in your report, you can access the calculated value using: = Fields! Total.Value.

Thus, you get your calculations without changing the underlying data source, it is more convenient to maintain (calculation in one place), it simplifies the link to the calculation throughout the report.

+3
source

It looks like you would like to make a link to the value of the report object (text field), and not to the column from the query. You can do this using ReportItems !.

When you drag a column from a dataset, it may name the text field after the column, if the column name may differ, you will want to assign a static value to the text field in which the value will be displayed.

So, in the initial example that you specified, you will have text fields named Item1, Item2 and Total. So in the corresponding Total textbox you want:

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

or if you named the Red and Blue text boxes, it will be:

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

alt textalt text

A list of available ReportItems will appear when you press '!' after ReportItems.

+4
source

I will just make an addition in the query and return it as a computed field.

eg.

 SELECT field1, field2, field1 + field2 AS total; 

I do not see a maintainability problem with this. If you need to leave the request separate from everything else, consider stored procedures or some kind of factory to generate the request.

+3
source
+2
source

Source: https://habr.com/ru/post/1333865/


All Articles