get previous total from filtered amount in crystal report - vb.net

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.

Related

Sum Calculation for Tax

Can you please help me on Crystal Report, where I'm trying to create a formula.
Case:
I have 2 tables, Table1 has some columns (like ItemName, ItemPrice, TaxType, TaxRate).
Table2 has Items sold with columns (like ItemName, Qty, ItemPrice, ItemTotal).
I have also linked the column in crystal report for ItemName, so that they can fetch related data.
I am looking for a formula in crystal report that can sum up tax rate * item total where tax type= VAT and TaxType= GST
My formula structure will be like:
VATSum ({table1.taxrate}*{table2.totalamount}) where table1.taxtype= 'VAT'
GSTSum ({table1.taxrate}*{table2.totalamount}) where table1.taxtype= 'GST'
Please guide.
I would really appreciate any body's efforts to solve this problem.
In Group Expert you will want to begin by creating a Group on the {table1.taxtype} field. This will ensure all of your VAT and GST items sold are grouped together. If you have other taxtype values than VAT and GST you will need to decide how to handle those taxtypes. You use Select Expert to filter them out if they are not needed for the report, or do nothing and they will all appear within additional groups on the report by their taxtype values.
You will need to then create a formula field that can be used to calculate the tax for each item sold. The name of this formula will be referenced by other formula fields in the report, so I will call this formula field itemTax in this example. The formula for this field will be:
{table1.taxrate}*{table2.totalamount};
Place the itemTax formula field into the details section of the report.
From here you have 3 options on how to calculate the sum of itemTax. You may insert a Summary Field, a Running Total Field, or another Formula Field. Any of them will work for you, but I will continue with the Formula Field option.
Create another formula field and name it totalTaxByGroup. The formula for this field will be:
Sum({#itemTax}, {table1.taxtype});
Then place this formula field in the Group Footer section of the taxtype group.

Selection Formula where value is in a DataTable

My system has a database table for orders (Sales Lines) and a table that stores customer addresses (Customer_Addresses). Each customer may have up to 10 addresses.
I need to create Crystal Reports to get all orders between a specified date range, where the customer is in a selected country. Such as between 01/01/2016 - 31/12/2016 in the UK.
I have considered selecting all address codes where Country = selected_country from Customer_Addresses, then storing the results in a DataTable. Then I'd use a selection formula of {Sales Lines.Order_Date} >= myDate AND {Sales Lines.Order_Date} <= myOtherDate AND {Sales Lines.Address} = (One of the codes within the DataTable)
What code would I need after {Sales Lines.Address} = to search for records where the address code in Sales Lines.Address is also stored in the DataTable I created when selecting from Customer_Addresses?
Crystal Reports has a simple functionality for this kind of tasks:
Just join from Sales Lines to Customer_Adresses.
Now you can set your date filter and your country filter directly.
You will have duplicates in your data if more than one customer address for the same order matches with the country code. But this is no problem. Crystal Reports has a option to enforce distinct data. Just activate this option in the database menu (it will use a DISTINCT in SQL)...

Excel VBA - Find first instance of value after another value

The example is created to help illustrate my problem.
I have a table of values the following table in Excel:
A B C D
Total Inventory £55,000 Customer 3
Work In Progress £20,000
Completed Goods £35,000
Total Inventory £60,000 Customer 4
Work In Progress £30,000
Completed Goods £30,000
Total Inventory £20,000 Customer 2
Work In Progress £5,000
Completed Goods £15,000
Total Inventory £2000 Customer 1
Work In Progress £1500
Completed Goods £500
When the table is generated the customers in column D (and the corresponding information in the other columns) appear in a random order. I'd like to extract the "Total Inventory" figure for Customer 4. As such I am wooking for a way to search for "Customer 4" in Column D and then extract the first "Total Inventory" figure which occurs in Coloumn A after that.
I know how to do a VLookup using VBA and extract the figure from Column B but I don't known how to make sure that I extract the correct "Total Inventory" figure when the order of the customers changes each time the table is generated.
Any suggestions would be appreciated!
Thanks
Sub Macro1()
Dim cust As String
cust = "Customer 3" ' it can be any other varible I just used this to check the data
formu = "index(b:b,match(""" & cust & "Total Inventory"",c:c&a:a,0),1)" ' this one will run to lookups and make sure that correct line with 2 lookup values
Result = Evaluate(formu)
MsgBox (Result) ' again I entered this just to see that this is working
End Sub
Text inline. Tested and validated.

Making Excel report into SSRS with Pivot Tables

I am trying to create a SSRS report from an ad hoc script I have. I can get results but the user of the report requests certain pivots that I can not seem to correctly display the information.
Below is an export of the report from sql with the pivots added. I want each row to be grouped by the GRADE first, OD second, and ID third. The pivot is adjusted for the STOCK NUMBERs. Each row with matching grade,OD, and ID will have numerous stock numbers.
http://i.imgur.com/Bx3yMuX.png
This is the closest I have have came to displaying the information in SSRS.
http://i.imgur.com/hpajKmB.png
Is there anyway I can have the Stock numbers run across a single row instead of a row for each stock number?
I would create a Column Group based on Stock number. That will generate a column for each Stock number.
It was a little more tricky than I thought. Since I did not want the Stock Number to actually be a column header but to just list on each column corresponding to my group it was not an actual pivot and was why it was not working properly.
Basically to get it to work I had to use the LookUpSet+Join function in SSRS to list the stock numbers out. I was not required to list them out on different columns. Thank-you for your replies.
Here is the code I used in the column
=Join(LookupSet(Fields!grade.Value & Fields!od.Value & Fields!wall.Value & Fields!id.Value, Fields!grade.Value & Fields!od.Value & Fields!wall.Value & Fields!id.Value, RTrim(Fields!stock_number.Value), "FOC"), ", ")

Crystal Reports equivalent of 'WHERE'

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.