how to calculate sum of row in crystal report using sql query, and do not display if the sum equals to 0.00 - mysql

I have the following crystal report, I want to calculate the sum of each row of specific columns:
Opening Quantity
Purchase Quantity
Issue Quantity
if sum of the above 3 columns is equal to 0.00, then do not print that record.
Please look out at the screenshot of generated report:

I am to guess here that the fields are placed in the DETAIL section , if then you can use the suppress formula(Section Expert-->Detail Section-->Suppress formula)
and try something like this
{Opening Quantity field} + {Purchase Quantity field} + {Issue Quantity field} = 0

I think this can give some idea to you
1) you have to create a formula to sum up the opening quantity, purchase quantity and Issue quantity by using Running Total Field.
Let say your field name for opening quantity inside the TableA is 'opening quantity'.
Thus, choose Table A, inside the Running Total Field and find the 'opening quantity'.
Then, choose 'SUM' as Type of Summary.
Do the same for another two fields.
At last, you will have 3 different running total field formula.
2) combine together these 3 formula inside one new formula.
Your final formula should look like this.
Let say you name it as Formula 4
if {#Formula1}+{#Formula2}+{#Formula3}<>0 then {#formula1}+{#formula2}+{#formula3}
then you drag this formula to any space in the report that you want the total to appear.
3) After drag it, right click on the formula and press 'Format Object'
Check the suppress box and write this inside the blue cross tab beside the suppress checkbox
{#Formula4}=0

Related

SSRS Report - Badges

Is there an easy way to do a page of badges in an SSRS report? I am looking at 2 across and 3 down per page based on a list. I have built one so far of a single column using a list box but the problem is that it is not advancing to the next record and shows me the same record over and over until I get to the end of the count of total records in the dataset so I know I am doing something wrong. I am using Visual Studio 2017
I use a matrix when I am making a grid with boxes that go across and down.
First I add a ROW_NUMBER to the query to have the order in which to show the records. I subtract 1 so the values start with 0.
SELECT *, ROW_NUMBER()OVER(ORDER BY EFF_DATE) - 1 ROW_NUM
FROM BLAH_BLAH...
Then in SSRS, add 2 Calculated Fields to the dataset with the ROW_NUM.
The first is named ROW. It will have an integer with the row that the record will end up in.
=INT(Fields!ROW_NUM.Value / 2)
The second is COLUMN that will give the a column number.
=Fields!ROW_NUM.Value MOD 2
Then in the matrix, set the grouping based on the calculated fields.
COLUMN GROUP
Group and Sort by COLUMN
ROW GROUP
Group and Sort by ROW
The 2 can be changed to use whatever number of columns is needed.

Calculate Min and Max for aggregation in SSRS report

My SSRS report have a dataset that will return the following result. The result set for some reason may not be changed. Note that Category - SubCategory pair might not be distinct.
Category Sub-Category Value
-----------------------------
A A1 100
A A2 120
A A2 60
B B1 80
B B2 90
B B2 70
I want to show the max value and main value for each of the SUM(category, subCategory) in report matrix, as exactly the format as follows (except the comment in bracket):
Max | 180 (two A-A2 rows)
Min | 80 (B-B1)
How can I define the matrix and write the expression? If make a group on these two columns, The matrix will show four rows regardless of what expression I set.
I tried to run your use case on my local SSRS.
On Left hand side I have original Data and on Right hand side I have the desired result you expect.
What you need is grouping as below
Expression for sum as below
Put a tablix into your report. Then at Row Groups (bottom) click on the (Details) and chose Add Group > Parent Group. Click the Add group header and chose your Sub-Category. Do the same with your Category. Your Row Grouping hierarchy should be now Category > Sub-Category > Details.
Now you see the brackets on the left in your tablix, they indicate the level. If you use now the following expression with their group name on the specific level, you will get what you want.
'At the Category group level header
=Sum(Fields!Value, "CategoryGroupName")
'At the Sub-Category group level header
=Sum(Fields!Value, "SubCategoryGroupName")
I got the way to make it. The solution is as follows:
Make a row parent group called row. Let the group group by a constant.
Make a child group category under the row group which is grouped by Category.
In matrix cell which is inside the group, Add this expression: =Min(Sum(Fields!Value.value), "Category"), "row"). that's the reason why I make a constant group, because I want to make the nested aggregate function legal.
This expression will return all values identical within the Category group. Now add another row outside of these row groups. Pick a cell and enter =ReportItems!ThatTextBox.Value.
Hide the row which consists your groups.
Do the same for MAX value (Start from adding an adjacent group, grouping by constant)

How to Combine Fields from Two Datasets SSRS?

I am working on a report to show the total number of hours an employee spent working. Our company tracks labor hours by Service Request and Work Order so I need to bring totals for each into the report.
I created two datasets- one for Work Orders and one for Service Requests. Ideally, I would like to combine the total number of Work Order hours with the total number of Service Request hours and present that number listed by employeeID since both datasets have the employeeID field.
I thought it would be as simple as:
=(SUM(Fields!TOTALHOURS_WO.Value, "DataSet1") + SUM(Fields!TOTALHOURS_SR.Value, "DataSet2"))
I don't get an error, however, I am getting a number which repeats for each employee so I know I'm doing something wrong.
Any help is greatly appreciated.
Mal,
As #StevenWhite mentioned, LOOKUP is probably the function you are looking for.
Here is an example for you. For the example datasets:
EmployeeID | TOTALHOURS_WO
-----------------------------------
123 | 12
456 | 3
EmployeeNum| TOTALHOURS_SR
-----------------------------------
123 | 2
456 | 5
You will note that each table in a SSRS report needs a DataSet assigned to it. I will assume your table is using our first DataSet, which we will name "DataSet1". The second dataset above will be "DataSet2".
For your total hours you will use an expression. It should look something like this:
=TOTALHOURS_WO + LOOKUP(Fields!EmployeeID.Value, Fields!EmployeeNum.Value, Fields!TOTALHOURS_SR.Value, "DataSet2")
So you will be adding the TOTALHOURS_WO from your local dataset to the result from the LOOKUP function. What lookup is doing is taking the first field from your local dataset, finding a match in the dataset provided to the function (as a string), and returning the field from the row it matched to. The last parameter is the dataset to search.
Just in case you get an error... it's always a good idea to cast data to the type you want to work with in case it comes in wrong. So...
=CINT(TOTALHOURS_WO) + CINT(LOOKUP(Fields!EmployeeID.Value, Fields!EmployeeNum.Value, Fields!TOTALHOURS_SR.Value, "DataSet2"))
This assumes you have a one to one match on employee ID. If you have to SUM both fields you can try this:
=SUM(CINT(TOTALHOURS_WO)) + SUM(LOOKUPSET(Fields!EmployeeID.Value, Fields!EmployeeNum.Value, CINT(Fields!TOTALHOURS_SR.Value), "DataSet2"))
SUM for TOTALHOURS_WO will give you the SUM in your current table group (so make sure you are grouping by staff ID in the table). It will then add it to the SUM of LOOKUPSET. LOOKUPSET works the same as lookup but returns an array of matches instead of the first.
Hope this helps.

Interactive sorting In SSRS on Values - Matrix report

I want a interactive sorting in SSRS matrix report. From database we are getting 3 columns -PrimaryKey,Columns and Value.
We are grouping rows by Primary Key and grouping column by Columns and use Value as data.
My Matrix Report -
ID [Columns]
[Primary Key] Values
Output of the Matrix report -
ID FirstName MiddleName Lastname
1 Rajiv Jha Sharma
2 Prem Kumar Bose
3 Usha Shamila Praveena
I am able to use the interactive sorting on ID because ID is group by rows but I want to use the interactive sorting on dynamic cloumns values like FirstName,MiddleName and LastName.
Expected result when we interactive sort on Lastname
ID FirstName MiddleName Lastname
2 Prem Kumar Bose
3 Usha Shamila Praveena
1 Rajiv Jha Sharma
Thanks for any Help.
Are you using the report wizard to build this? You should be able apply the interactive sort using the properties menu on the column groups.
By adding an interactive sort button to a column header you can allow a user to click the column header and sort the parent group rows in a table or matrix by the value displayed in that column. The order of child groups remains unchanged.
To add an interactive sort button to a column header to sort groups:
In a table or matrix on the report design surface, right-click the text box in the column header for the group to which you want to add an interactive sort button.
Click Text Box Properties.
Click Interactive Sort.
Select Enable interactive sort on this text box.
In Sort, click Groups.
From the drop-down list, select the name of the group that you are sorting. For groups based on simple group expressions, the Sort by value is populated with group expression.
For more info, see this article: http://technet.microsoft.com/en-us/library/cc627509(v=sql.100).aspx
Quite an old question, but I stumbled upon similar problem recently.
Though SSRS does not allow you to add interactive sorting on dynamic columns in a matrix, you can simulate similar behaviour. I've figured out a method, which require the report to fire itself (through go to report action) sorted on desired column.
I will use a bit more complicated example to show the full functionality of this solution.
Imagine an online bookstore, which would like a report showing their customers (rows), number of books (values) and total value of books (values), which they bought, by category – Fiction/NonFiction in my example (columns). Of course they want to see their best customers, so the sort will be descending.
Example data that we are getting from the database:
UserID Columns BooksCount BooksValue
AliBaba Fiction 2 25.96
AliBaba NonFiction 4 112.00
ThomasJefferson Fiction 3 36.83
ThomasJefferson NonFiction 1 46.80
BillCosby Fiction 10 536.47
BillCosby NonFiction 2 26.87
The report will look like this:
[Columns]
Books Count Books Value
[UserID] Values Values
I would like the report to be able to sort by “Books Count” or “Books Value” for any Column. Here are the steps to follow:
You need to add parameters that will store the name of the column to sort on - #SortColumn and the metric name (counts or values) to sort on - #SortMetric.
Go to “Books Count” textbox and add action "Go to report" specifying the same report. Add #SortColumn parameter with a value from [Columns] field in the underlying dataset. Add #SortMetric parameter with value set to “BooksCount”. Similar for “Books Value” textbox.
You can adjust the column header text with following expression, which will show the user on which column data is sorted:
= IIf( Parameters!SortColumn.Value=Fields!Columns.Value And Parameters!SortMetric.Value = "BooksCount" ," ^","")
This was for “Books Count”, you can add similar for “Books Amount”
Finally the magic that happens on the database site. Source table is named [Sales]. Apart from the sorting, below code allows to select only top N rows if your dataset is larger.
You can create a dataset using this code or better create a stored procedure. And join report parameters with dataset parameters.
DECLARE #TopN INT = 50
;WITH Users_Sorted AS
(
SELECT
UserID
,ROW_NUMBER() OVER (ORDER BY
CASE #SortMetric
WHEN 'BooksCount' THEN Sales.BooksCount
WHEN 'BooksValue' THEN Sales.BooksValue
END DESC) AS ROWNO
FROM Sales
WHERE
Sales.Columns = #SortColumn
)
,Sales_MAIN AS
(
SELECT
Sales.UserID
,Sales.Columns
,Sales.BooksCount
,Sales.BooksValue
,ISNULL(Users_Sorted.ROWNO,
ROW_NUMBER () OVER (PARTITION BY Sales.Columns ORDER BY Sales.UserID ASC)
) AS ROWNO
FROM Sales
LEFT JOIN Users_Sorted ON Sales.UserID = Users_Sorted.UserID
)
SELECT * FROM Sales_MAIN WHERE ROWNO <= #TopN ORDER BY ROWNO

Chart related query: adding new category field manually

I am trying to create a chart using SSRS 2008. I've got 4 category fields:
field 1
field 2
field 3
field 4
I want to add another category field in the chart which will be a total, e.g.:
field 1 + field 2 + field 3 + field 4
Now I don't know how to do it. Field 1 through field 4 come from a table directly, but because field 5 is the total I dont know how to add it manually?
In the Category field of the chart, I have used group on(column name) and want to add another field in the chart which will be the total.
I have even tried this :-
=Fields!ColumnName.Value.Equals("ABC")+Fields!ColumnName.Value.Equals("DEF")+Fields!ColumnName.Value.Equals("GHI")+Fields!ColumnName.Value.Equals("JKL")
Please help!!!!
I would select the chart object, then click it again so the Chart Data pane appears.
Then I would click the + button next to Values, then choose Expression.
In the Expression I would enter something like:
= Fields!Field1.Value + Fields!Field2.Value + Fields!Field3.Value + Fields!Field4.Value
I would go back to the Dataset and add a UNION with a GROUP BY to generate a total row. I would overwrite the Field1-4 values with 'Total'.