My report is as follows:
One table provides financial information with sums at the group footer (Grouping is called "StockTable_Shipped"). The group is controlled by a boolean value (1=shows shipped data, 0 = shows received data)
The second table is a variance report for data that has been shipped (boolean value of 1) and has a sum at the bottom of the table.
My ultimate goal is to take the sum from table1 where shipped=1 and subtract it from the variance sum from table2.
This will be placed in a textbox at the bottom of the report.
I understand if this sounds confusing but I would be more then happy to provide more information.
If I were you, I would create a new calculated field which would hold the sum of all your Shipped Data (1's) not just the sum of all your data (1's and 0's).
After that, it should be as simple as putting in the expression that subtracts your calculated field from the Sum of your table2 field.
Related
I'm having an issue creating some grouping in SSRS. I can't use SQL.
Basically I have a set of data I want to turn into a pivot or summary table. I can SUM revenue by ownerID no problem, but they have some teaming and filters on their report I can't replicate. This is the basic table:
Employee Quote Revenue
User1 SUM by ownerID
User2 SUM by ownerID
User3 SUM by ownerID
User4 SUM by ownerID
User5 SUM by ownerID
User 6 SUM by ownerID
This is what they would like to measure
Teaming/Filter Quote Revenue
User 1 & User 2 SUM by Group
User 3 & User 4 SUM by Group
User 5 where customer type=1 SUM by Filter
User 5 where customer type=2 SUM by Filter
User 6 SUM by Owner ID
I've used SUM by a group name and I've tried SUM IIF but they either don't work or I get the revenue on separate rows. Would appreciate any advice.
Thank you.
My approach here would be to use a one row Tablix for each measure. That way, you can set the filter, and grouping for each scenario in its own Tablix, instead of attempting to do this in one. This keeps with the no SQL restriction. As far as display on the report, you can align each Tablix, and hide the headers, so it looks like one table in the end.
It’s not the most elegant solution in the world, but it should work.
More detail for one of the measures (User 1 and User 2 revenue):
Add a Tablix to the report
In the Tablix properties, set the dataset name to proper dataset
In the Filters properties for the Tablix, set the filter to what is need for the specific measure. You will have to use the In operator for the measures where you are teaming more than one user. In this case it will be something like “User1”, “User2” for the Value of a filter where the Expression is UserID, and the Operator is In. SSRS will change what the Value looks like in the designer, so you may have to play around with it duplicating quotes
In the Row Groups pane, for the (Details) row group, change the Group Properties group expression to use a field in the dataset that each row in the filter shares. Maybe a date, or a quote number in this case. You are not going to display this value so what it is is not important, just as long as it is the same for each row in the data you are filtering on.
In the first column of the Tablix, set the detail value to a string describing what you are showing, “User 1 and User 2”, in this instance.
In the second column of the Tablix, make the expression the sum of the revenue.
=Sum(Fields!revenue.Value)
Hide the header row
Run the report
I know this is a lot, but once you do one, you can copy and paste the Tablix, and adjust to new copy for the next measure. Hopefully, you don’t have a ton of measures! If you do, then a really need to think about doing this with SQL.
I have SSRS report where in I am using table with 7 columns (Date, Job ID, Job Name, Status, Output Count, Expected Count, Flag). Out of 7 columns , 4 are directly coming from dataset. Rest three (Job Name, Expected Count, Flag) are calculated columns. I am getting their values from either SSRS custom code or expression. I want to count those rows where Output Count and Expected Count are not matching. Also I have Flag column where I am using Background Color property to check if values are matching or not. So even if I can get count of rows having Red background at Flag column will also server my purpose. Please help me in achieving the same.
You can create some new fields for your dataset to handle calculated values. Then, in your report, you can add some groups and add count or sum values on the table.
I have an SSRS Report, in the database there is a column by name Total_running_hours.
There are more than one record for a single Cycle_number like more than 1 row with same Cycle_number but different Block_numbers and the value in Total_running_hours field will be same for all the rows with same Cycle_number. Eg. 1 Cycle number with 4 diff block_numbers contain same Total_running_hours for all 4 rows.
Now the problem is, in the group footer if I put this field then it will show the Total_running_hours value only once which is correct, but my final requirement is,
I need to get the sum of this field in the Report footer which need to display the sum group wise. No matter how many rows are there for a single Cycle_number it has to take only once and display the result.
I tried in different ways like
=sum(ReportItems!textbox204.Value) // name of text box in Group footer
Error: Report item expressions can only refer to other report items
within the same grouping scope or a containing grouping scope.
=sum(Fields!total_running_hours.Value,Group_name)
Error: The scope parameter must be set to a string constant that is
equal to either the name of a containing group, the name of a
containing data region, or the name of a data set.
Can any one please help me in getting the sum Group wise
Thank you in advance.
I found solution for this Problem.
We cannot simply sum the Total_Running_hours value as this would give us duplicates and the incorrect answer. We cannot sum the reporting services group as it goes out of scope
There is no SUM DISTINCT available in Reporting Services 2005 so we can't get the distinct value that way.
Since the query may not return a particular Cycle_Number Type we cannot use that as a filter.
The solution found was to add a column of the row number within a windowed set partitioned by the Cycle_Number like this
ROW_NUMBER() OVER (PARTITION BY Cycle_Number ORDER BY Cycle_Number ) AS 'RowNumber'
Then in the reports’ footer total column we put an expression that only takes the first row’s value to sum and converts all other rows to zero in that windowed set.
=SUM(IIF(Fields!RowNumber.Value=1,Fields!Total_Running_hours.Value,0))
After using this if u found any error in textbox like #Error
Then try this
=SUM(IIF(Fields!RowNumber.Value=1,CDbl(Fields!Total_Running_hours.Value),CDbl(0.0)))
I am trying to build an access report based on data from multiple different tables within the database.
I have 3 columns which perform calculations, and I am wondering how to put this query together. All 3 columns deal with dates, but calculate them differently.
The first column retrieves the most recent date of action for a userid if the type of action is "B":
select pid, Max(date) as most_recent
from actions
where ref = 'B'
group by pid;
The second column performs a calculation based on 2 fields, one is a date and one is a number in months. I am unsure how to add these two fields so that the number is added to the date as a number of months.
what i have so far is:
select nummonths,Max(lastvisit) from users
the third column I need to select the first date thats in the future for each user (next appointment date), there will be dates before and after this date so its a little difficult:
select uid,date from visits
The code for the last 2 queries needs to be slightly modified, and I was wondering what the best approach would be to join these all together? A type of join?
If you need to build a report with data from the 3 queries, you will need related data to join them. In that case, please send the structure of the tables.
If you need to show 3 lists in one report, you can use subreports: create a new empty report. In design mode, you can add 3 subreports from the toolbox bar. To each of the subreport assign the record source property to the corresponding sql.
regards
I am unsure how to add these two fields so that the number is added to the date as a number of months.
Use the DateAdd() function:
SELECT DateAdd("m", 2, LastVisit) FROM ...
Results in a date two months from the LastVisit date.
This seems like it should be simple but I can't find anything yet. In Reporting Services I have a table with up to 6 rows that all have calculated values and dynamic visibility. I would like to sum these rows. Basically I have a number of invoice items and want to make a total. I can't change anything on the DB side since my stored procedures are used elsewhere in the system. Each row pulls data from a different dataset as well, so I can't do a sum of the dataset. Can I sum all the rows with a table footer? Similarly to totaling a number of rows in Excel? It seems very redundant to put my visibility expression from each row into my footer row to calculate the sum.
A few ways you could achieve this:
1. Do the calculation in the SQL and sum that field, like so:
SELECT Quantity, Amount, Quantity * Amount As TotalAmount FROM MyTable
Then just use the TotalAmount field in your Detail row and sum it in the footer.
2. Create a second Dataset that calculates the total for you and use that in your footer instead of a sum:
=Sum(Fields!TotalAmount.Value, "MyTotalingDataset")
3. Do it using custom code. Right-click on the Layout space choose Properties and click on the Code tab. Put in the following code:
Public Dim TotalAmount As Double = 0
Public Function CalculateRowTotal(ThisValue As Double, ThatValue As Double) As Double
TotalAmount = TotalAmount + (ThisValue * ThatValue)
Return ThisValue * ThatValue
End Function
On the Detail band, make the column where you sum the field have this expression:
=Code.CalculateRowTotal(Fields!Quantity.Value, Fields!Amount.Value)
This will execute the code above and do your calculation plus calculate the total sum in the process.
The Footer band displays the total sum so the column has the expression:
=Code.TotalAmount
And you're done. Just be careful because you aren't guaranteed the order in which your code will execute and for some reports it will execute the footer first (for example, if you use the Sum of the rows in the Detail band) which would make the total zero as the Detail band calculations haven't happened yet, but for the general case this should work.
You could change the db as follows.
Did you know you can get aggregated results in SQL without aggregating the data?
Just add an extra column to the dataset as follows:
,SUM(OrderQty) OVER(PARTITION BY SalesOrderID) AS 'Total'
In the above sample:
OrderQty is the value you wish to sum
SalerOrderID is the equivalent of 'GROUP BY'
You can use the same technique with COUNT, AVG and so on
More information here
http://msdn.microsoft.com/en-us/library/ms189461(SQL.90).aspx
In case you have a problem with the execution order, add a text box below of the table and display TotalAmount in this box.