Crystal reports subtrack running total - crystal-reports

I want to create a formula for running total subtract sales from opening stock. I have database fields for Opening stock and sales. From opening stock I have to subtract sale and show from second record
For example:
ID openingstock sales Stockonhand
--- ------ ------- -------------
1 500 10 500
2 5 490
3 10 485
4 3 475
5 5 472

Related

grouping rows data in tableau and get the result

I have a table in tableau
store year project store_amount
1 2012 p1 1200
1 2012 p2 1200
1 2012 p3 1200
2 2019 p4 1700
2 2019 p5 1700
3 2012 p6 2900
What I want in tableau is total store amount by store id, so it should show 1200 for store 1, 1700 for store 2, 2900 for store 3
And when I want to see the total store amount I want the sum of store 1,2,3 , 1200+1700+2900
Another grouping I want to do is by year: So for 2012 it should be (1200+2900)
I tried a lot of ways but can't do it.
There are a number of options, it basically depends on the specifics of what you're trying to do. Based on you wanting so sum the total across all stores and also group by year try the following calculated field formula:
{ FIXED [Store]:MIN([Store Amount])}
Sum this new field - in other words it's the sum of the minimum (or max or average - based on your data it doesn't matter) values

remove a lesser duplicate

In KDB, I have the following table:
q)tab:flip `items`sales`prices!(`nut`bolt`cam`cog`bolt`screw;6 8 0 3 0n 0n;10 20 15 20 0n 0n)
q)tab
items sales prices
------------------
nut 6 10
bolt 8 20
cam 0 15
cog 3 20
bolt
screw
In this table, there are 2 duplicate items (bolt). However since the first 'bolt' contains more information. I would like to remove the 'lesser' bolt.
FINAL RESULT:
items sales prices
------------------
nut 6 10
bolt 8 20
cam 0 15
cog 3 20
screw
As far as I understand, If I used the 'distinct' function its not deterministic?
One way to do it is to fill forward by item, then bolt will inherit the previous values.
q)update fills sales,fills prices by items from tab
items sales prices
------------------
nut 6 10
bolt 8 20
cam 0 15
cog 3 20
bolt 8 20
screw
This can also be done in functional form where you can pass the table and by columns:
{![x;();(!). 2#enlist(),y;{x!fills,/:x}cols[x]except y]}[tab;`items]
If "more information" means "least nulls" then you could count the number of nulls in each row and only return those rows by item that contain the fewest:
q)select from #[tab;`n;:;sum each null tab] where n=(min;n)fby items
items sales prices n
--------------------
nut 6 10 0
bolt 8 20 0
cam 0 15 0
cog 3 20 0
screw 2
Although would not recommend this approach as it requires working with rows rather than columns.
Because those two rows contain different data, they are considered distinct.
It depends on how you define "more information". You would probably need to provide more examples, but some possibilities:
Delete rows with null sales value
q)delete from tab where null sales
items sales prices
------------------
nut 6 10
bolt 8 20
cam 0 15
cog 3 20
Retrieve rows with max sales value for each item
q)select from tab where (sales*prices) = (max;sales*prices) fby items
items sales prices
------------------
nut 6 10
bolt 8 20
cam 0 15
cog 3 20

How to Sum values of column corresponding to one column in jasper

In jasper i have one requirement like, sum all the data of the column based on another column. I know how to show sum of all the data in the column. But please suggest me for this requirement.
Emp-Category Emp-Id Salary
---------------------------------------
Cate - A 1 128
2 50
3 89
total 267
Cate - B 4 123
5 50
6 100
total 273
Total Expenses 540
So there will be many number of categories, which will be getting from database.
Please suggest me how to do this approach.
In that case, you can use groups...
You can refer to the link below for tutorial :)
http://www.tutorialspoint.com/jasper_reports/jasper_report_groups.htm

Calculating MAX(DATE) for Value Groups Where Values Go Back and Forth

I have another challenge that I am trying to resolve but unable to get the solution yet. Here is the scenario. Pardon the formatting if it messes up at the time of posting.
ACCT_NUM CERT_ID Code Date Desired Output
A 1 10 1/1/2007 1/1/2008
A 1 10 1/1/2008 1/1/2008
A 1 20 1/1/2009 1/1/2010
A 1 20 1/1/2010 1/1/2010
A 1 10 1/1/2011 1/1/2012
A 1 10 1/1/2012 1/1/2012
A 2 20 1/1/2007 1/1/2008
A 2 20 1/1/2008 1/1/2008
A 2 10 1/1/2009 1/1/2010
A 2 10 1/1/2010 1/1/2010
A 2 30 1/1/2011 1/1/2011
A 2 10 1/1/2012 1/1/2013
A 2 10 1/1/2013 1/1/2013
As you can see, I need to do a MAX on the date based on each group of code values (apart from ACCT_NUM and CERT_ID) before the value changes. If the same value repeats, I need to a MAX of the data again for that group separately. For example, for CERT_ID of '1', I cannot group all four rows of Code 10 to get a MAX date of 1/1/2012. I need to get the MAX for the first two rows and then another MAX for the next two rows separately since there is another code in between. I am trying to accomplish this in Cognos Framework Manager.
Gurus, please advise.
The syntax for getting the max value for CERT_ID is:
maximum(Date for CERT_ID)
If you want additional level/s for max you can use the following syntax:
maximum(Date for ACCT_NUM,CERT_ID,Code)
In general, it is best practice to group and summarize values in report, not in framework manager.

Crystal report percentage difference between 2 columns in crosstab

Not sure if this is possible or not in crystal. I have a crosstab report that has 2 columns. I need to take the percentage between the 2 values. Here is a quick sample of what I need it to look like:
Type 1 Type 2 Type 3 Total
========== ========== ========== ==========
3/1/2011 2 1 50% 1 1 100% 0 0 0% 3 2 66%
3/2/2011 1 1 100% 3 1 33% 5 3 60% 9 5 55%
Total 3 2 66% 4 2 50% 5 3 60% 12 7 58%
To create column 1 I am just doing a distinct count. To create column 2 I created a formula to the field value to 1 if it is true and 0 otherwise. I set the 3rd column to take the percent by row. The problem is in the row total at the bottom. The counts are correct, but the percentage always shows up as 100%.
I am using crystal reports 2008.
I was able to finally figue this out.
In column 1 I added a distinct count.
Column 2 I added a count based off of a formula:
if MyType = "Whatever" then
1
else
0
The third column was an average (a built in function).
No groupings are needed.