Crystal Reports equivalent of 'WHERE' - sql

I'm familiar with SQL but not Crystal Reports. I'm trying to deal with an imported data set with 5 columns:
id deathDate giftDate giftAmount Dead
123 2008-01-06 2011-09-08 25.00 TRUE
456 2009-06-08 2011-10-13 10.00 TRUE
789 0 2011-12-04 50.00 FALSE
...
I'm trying to do a subquery but can't figure out what the CR equivalent of WHERE in SQL would be. I'd like to do something along the line of:
SELECT count(id) from tab1 where dead=TRUE
Any suggestions?

As Conrad and dotjoe have observed, the Crystal equivalent of the sql where clause is the Select Expert - you should be able to find this on the Report menu.
If you need to include both true and false Dead records in the detail section, but want a total for only those records where Dead is true, the simplest way to do this would be to set up a formula item. To do so:
Right-click on the Formula Fields option in the Field Explorer and select New... .
Enter a suitable formula field name, like DeadCount.
In the Formula editor, enter a formula like the following (assuming Dead is a string):
If {tab1.Dead} = 'TRUE' then 1
Use the x-2 button (or Alt-C) to check that the formula does not have any errors, then press the Save and Close button to exit the formula editor.
Drag and drop the new formula field from the Field Explorer onto anywhere in the report.
Right-click on the formula field that you have just added to the report and select Insert > Summary... from the menu.
In the Insert Summary dialog, specify the Summary operation as Sum and the Summary location as Grand Total (Report Footer), then click OK. A summarised field, labelled something like Sum of #DeadCount, should appear in the Report Footer. (You should now remove the un-summarised formula field from where you placed it in the report design area.)
This technique is essentially similar to including a summed case value in a sql query - something like: select sum(case when Dead = 'TRUE' then 1 end) as DeadCount from tab1

Add this to the record selection formula...
{datasetname.Dead} = true
//note: I'm not sure what data type that is but CR uses bool for bit and XSD bool
Then add a summary field to the report footer which does the count(id).
Or, if you need to display the dataset and only need a subquery you can use something called a "Running Total" field. In here you can do the count(id) and add the where clause to the necessary formula.

Related

Calculating the number of like records in an unbound text box on a form. in MS Access 2016

I have an unbound text box [txt_AmendmentOF] on a form to count the total number of Amendments a specific record has in the database. So the user knows which amendment they are on. Just a simple you are on Amendment 3 out of 8. i have this calculation i am using in the Control Source field of the text box [txt_AmendmentOF]:
=IIf(IsNull([txt_Amendment]),0,Count([MIPR_Number]))
there is a Field on my table called [Amendment] its text box on the form is called [txt_Amendment]. I have the calculation return a zero in [txt_AmendmentOF] if [txt_Amendment] is null. I need it to count the record number [MIPR_Number] that are the same and return the total number of Amendments count in the [txt_AmendmentOF] text box. on my table i have private key field called [ID] it is an autonumber format. The problem with the code above is it is counting all the fields that have a [MIPR_Number] and returning the total row count of that. i am not an expert here so any help would be greatly appreciated.
Update to post..
I have also tried this and got an error in the text box
=IIf(IsNull([txt_Amendment]),0,Count([MIPR_Number]=[txt_MIPR_Number]))
Counting by a condition is one of the basic dataabase tasks. To get answers from a db, you have to query the database (and that is done by createing a query).
To count same[MIPR_Number]you have to group the data (a group contains same numbers), then count.
SELECT COUNT(id) as CountOfSameNr, [MIPR_Number] FROM Table GROUP BY [MIPR_Number]
Store this query as e.g CountMIPRNumber.
Now you have two options:
Use a Dlookup to get one value
=IIf(IsNull([txt_Amendment]),0,Dlookup("CountOfSameNr","CountMIPRNumber","[MIPR_Number] = " & [MIPR_Number]))
or add the query to form recordsource (join on [MIPR_Number], "SELECT * FROM TABLE" is forms query)
SELECT CountMIPRNumber.CountOfSameNr, TABLE.* FROM TABLE LEFT JOIN CountMIPRNumber ON TABLE.[MIPR_Number] = CountMIPRNumber.[MIPR_Number]
and reference the count field
=IIf(IsNull([txt_Amendment]),0,[CountOfSameNr])

Sum rows in SAP Webi 4.1 report

I have a report in Webi which is similar to below example (Upper table).
What I want to build is the lower table, i.e. to sum up the values of "A" and "B" and show it in one row.
How to achieve this in BO Webi?
If you are on BI4, then this is actually pretty easily done. First, Control-click on the A and B cells to select both:
Right-click on one of the selected cells, then hit Group -> Group:
Give the group a meaningful name (taking the name "A+B" from your example):
This will create a new Group and replace the original variable in the report block:
You'll see the new variable under "Variables" in the Available Objects panel, and can modify it from there if necessary.
If you are not on BI4, or if you just prefer to enter a variable manually, you can do that too. Replace the Forecast column with:
=If [Forecast] InList ("A";"B") Then "A+B" Else [Forecast]

get previous total from filtered amount in crystal report

I have created the following report in Crystal Report using VB.Net 2012. The OPENING BALANCE & NET TOTAL rows are not in my report but my question is there.
TR_ID | TR_DATE |DETAILS | EXPENSE | INCOME | BALANCE
OPENING BALANCE 0.00
1005 08/24/2015 CASH RTN 0.00 10,000.00 10,000.00
1013 08/25/2015 PURCHASE 3,500.00 0.00 6,500.00
1014 08/25/2015 DEPOSIT 5,000.00 0.00 1,500.00
1013 08/27/2015 SALES 0.00 4,000.00 5,500.00
NET TOTAL 5,500.00
I filtered the specific records within the date range of 08/25/2015 and 08/26/2015 & it works well. My question is how I get the previous balance (10000) of the specific date (08/25/2015) in "OPENING BALANCE" row and the total balance in "NET TOTAL" row?
As per the given datas above, the report shows the 4 records well excluding the rows of OPENING BALANCE & NET TOTAL. I want to add the OPENING BALANCE row to show the opening balance of every vendors' accounts when I open the report. And if I view the records of a particular customer within a date range, then OPENING BALANCE row should show the previous balance until the start date of the given date criteria. Ex: If I select records from 08/25/2015 to 08/26/2015 as per above datas, the report will show the two particular records (2nd & 3rd). But I want to show the previous balance 10,000 or the total amount which is above to the star date (08/25/2015) should be shown in the OPENING BALANCE row. And the sub total amount of this vendor's
should be shown in the last NET TOTAL row. So, pls help me, how the formulas will come & how to do.
Thank you
I expect your great help
Thank you
It´s not too much clear to me, but you may try to get the values directly from the report using a variable to do it.
With the report opened, you may entry in the CrystalReport option and select "Selection Expert - Saved Data".
You must create a formula using the "Formula Field" at left panel, and build it using the top 3 windows:
The first top window shows the fields of the table your report handles;
The middle top window show some built-in formulas
SO, you must
Go to formula field and create a new one;
Select the field at the top-left window you want to get (the Openning)
Drag-drop it into the main window (below the 3 top selections) and save it as a new variable
Add this variable into your report. This way, you may get this field for calculations in the same report.
Is it you need to do?
Sorry if I cannot understand exactly what you need.
Hugs!
UPDATE
You may have TOTAL creating a formula of SUM within report.
Click on the field EXPENSE (which appear in 3 rows) and select in menu: CRYSTAL REPORTS - INSERT - SUMMARY. It will create a field that must be positioned at the bottom (in the new Group will be created).
Do the same with INCOME field.
Create a FORMULA FIELD at the bottom to calculate the difference between both SUMARIES. You can name each of these summary fields (like IncSum and ExpSum) and put in that third field: IncSum-ExpSum. You may also put them as invisible.
Your final balance should be:
OldBalance (the parameter I point next lines)
+
Movement (the field that reflects IncSum-ExpSum)
To get the last/old Balance, you may have to get it from code as pass it as a PARAMETER. To do this, create a parameter in te report: see in the FIELD EXPLORER you have a choice of PARAMETER FIELD. AFter create it, use this code:
Dim MyCrystalReportt As New ReportDocument()
MyCrystalReportt.Load(Application.StartupPath & "\ReportSample.rpt\")
MyCrystalReportt.SetDatabaseLogon(UserID, Password, DataSource, InitialCatalog)
Dim myLogonInfo As New TableLogOnInfo()
Dim myTable As Table
For Each myTable In MyCrystalReportt.Database.Tables
myLogonInfo = myTable.LogOnInfo
myLogonInfo.ConnectionInfo.ServerName = DataSource
myLogonInfo.ConnectionInfo.DatabaseName = InitialCatalog
myLogonInfo.ConnectionInfo.UserID = UserID
myLogonInfo.ConnectionInfo.Password = Password
myTable.ApplyLogOnInfo(myLogonInfo)
Next
MyCrystalReportt.SetParameterValue("Data1", LastBalance.Value.ToString)
ReportsForm.CrystalReportViewer1.Reportsource = MyCrystalReport
ReportsForm.show
Notes:
You may have a form (ReportsForm) with a Crystal Control within (CrystalReportViewer1).
Datasource is the Server Name or IP
InitialCatalog is the Database (not the table!)
The ParameterValue MUST be a string - is numeric is required, convert it to number inside the Report. Use a temp_field to get it (see formulas of Crystal and you will find some to make this task).
I hope it can help you.
Good luck.

Multisearch form for a query in access

I should make a query in Access that have 4 criteria. If I Run this query by the structure view of the query it works. Then I built a form to insert the criteria in 4 text boxes and get more easy the use of the query. I create the form using the tutorial on the official site of microsoft 1; i tried first the query with only one text box and one criterium and it works; when I use 4 text box, following the tutorial, it doesn't work. The criterium that I use for each field in the query is the follow:
Switch(Not IsNull([Forms]![frmRICmp]![cod]),[Forms]![frmRICmp]![cod])
I tried to use also
IIf(IsNull([Forms]![frmRICmp]![cod]), Like "*", [Forms]![frmRICmp]![cod])
but also in this case it doesn't work.
can someone tell me the right instrtuction to use in the query's criteria
tnks
So if I gather correctly you need to perform a multi search where if any of the boxes are null you would like to return all the values. and more than one text box can be used simultaneously. TO do this you have to amend do the following.
Amend the Query Field (Note i'm referring to field and not criteria)
For the first Text Box Assuming name is COD and Field Name is also COD
If the Current field name is COD insert another field with the same name and amend to
[COD]=[Forms]![frmRICmp]![cod] OR [Forms]![frmRICmp]![cod] Is NULL
then in the criteria field use the following value
TRUE
For the second Text Box Assuming name is COD2 and Field Name is also COD2
If the Current field name is COD2 insert another field with the same name and amend to
[COD2]=[Forms]![frmRICmp]![cod2] OR [Forms]![frmRICmp]![cod2] Is NULL
then in the criteria field use the following value
TRUE
and continue the same process for all 4 text boxes.

How to assign one same label for multiple value in non-queried available values in ssrs 2005 report?

Parameters - Multiple Values For One Label - Possible?
Sorry my modified Question.....
I have question to ask,...
Is it possible to have multiple values for ONE label in non-queried available values in SSRS 2005? i want to join fields value in a single row like,
Works: (But this bring a long list in drop down menu - which i donot want)
Label Value
---------------------------
Site-1 150
Site-1 151
Site-2 152
Site-2 153
Required result (Which i want - in one line)
Label Value
---------------------------
Site-1 150,151
Site-2 152,153
(which will bring one label and related multi-value in drop down or combo box.
But the problem is that ColumnName IN (#Site) does not work with multi-value.)
More description of the problem:
Let say, I have a field/column
Name = Site
Value = C150,C151, C152, C153
I want drop down menu on report with
C150,C151(as Site-1) & C152,C153(as Site-2)
So I created parameter i.e. #getSite and set values as
multi-value in the report as
Label Value
---------------------------------------------
Site-1 (150,151)
Site-2 (152,153)
And set my parameter as #getSite:= Parameters!#getSite.Value
And Query i wrote as,
SELECT * FROM ..
WHERE Site IN (#getDisease)
But after all these, my report result is empty,literally no result.
It seems like if i select only one value as Site-1 = 150, then it works
but not two or more values in one line,
why it is not possible?? if yes then how?
Please help!!!
Yes just Right Click on your parameter in your Report Data window under Parameters folder and select the check box for allow multiple values as follows
this is what I said before you need to put your column name inside a set of paranthesis something like this
SELECT * FROM ..
WHERE (Site IN (#getDisease))
I have been working on this problem for a while and I think I have finally figured it out...
Basically you need to use a backwards case statement in your SELECT statement, put that in a derived query and then reference it in the outer WHERE clause..
SQL:
SELECT * FROM
(
SELECT
Label
, value
, CASE WHEN [value] IN (150,151) THEN 'site-1' WHEN [value] IN (152,153) THEN 'site-2' END AS [grouped_values]
)
WHERE grouped_values IN (#getSite);
*Note: This answer only works on values that are mutually exclusive, if both sets had the same value included then it would be problematic..
--
Hopefully this can put you in the right direction. I am finding a lot of the reporting services tricks require reverse engineering or at least some reverse thinking.
cheers,
Michael