Any other way to count group records in crystal reports? - crystal-reports

I want to count the total no of records found under a group and according to that i need to assign reduction percentages.
In Detail,
if a user got less than 3 products he ll get 10%
if a user got 4-10 products he ll get 15%
if he got 10-20 products he ll get 20% as deduction
For example consider the following as a crystal report:
User 1
Product Deduction
Apple 15 %
Orange 15 %
Lemon 15 %
Strawberry 15 %
Grapes 15 %
Here i made a count of records in this group using running total and worte a formula. Depends on the count its ll make the deductions
But the problem in getting is, I'm getting the following output...
User 1
Product Deduction
Apple 10 % // Since count is 1
Orange 10 % // Since count is 2
Lemon 10 % // Since count is 3
Strawberry 15 % // Since count is 4
Grapes 15 % // Since count is 5
I wanna make all products deduction as 15 % if the total no of records are 4-15. Here the total no of products is 5 its in the range of 4-15 so all the product should have the deduction as 15 %.
Please help me out to solve this?

You don't need a running-total field (RT) for a simple count; use a summary field instead. The summary field can be used in the group's header and footer (a RT can only be used in the footer).
Select a field (preferably a unique field), then select Insert | Summary Field... Choose Count or Distinct Count from the picklist.
You can use this summary in a formula as well:
//{#discount}
//Assumes there is a group on {table.fruit_name}):
SELECT Count({table.key_field}, {table.fruit_name})
CASE 1 to 3: .1
CASE 4 to 5: .15
DEFAULT: 0

Related

Running total using two columns

Given a table with data like:
A
B
Qty.
Running Total
5
5
5
10
5
15
I can create the running total using the formula =SUM($A$2:A2) and then drag down to get the running total after each quantity (here Qty.)
What may I do for calculating running total using two columns which may or may not be consecutive as shown below:
A
B
C
D
Qty. 1
Other
Qty. 2
RT
2
blah
2
4
2
phew
2
8
3
xyz
2
13
Place in cell D2 the formula =SUM(A2,C2,D1). Do not pay attention to the fact that the function will refer to a non-numeric cell D1 - the SUM() function will not break, unlike ordinary addition =A2+C2+D1. Now, just stretch the formula down.

Calculating group means with own group excluded in MATLAB

To be generic the issue is: I need to create group means that exclude own group observations before calculating the mean.
As an example: let's say I have firms, products and product characteristics. Each firm (f=1,...,F) produces several products (i=1,...,I). I would like to create a group mean for a certain characteristic of the product i of firm f, using all products of all firms, excluding firm f product observations.
So I could have a dataset like this:
firm prod width
1 1 30
1 2 10
1 3 20
2 1 25
2 2 15
2 4 40
3 2 10
3 4 35
To reproduce the table:
firm=[1,1,1,2,2,2,3,3]
prod=[1,2,3,1,2,4,2,4]
hp=[30,10,20,25,15,40,10,35]
x=[firm' prod' hp']
Then I want to estimate a mean which will use values of all products of all other firms, that is excluding all firm 1 products. In this case, my grouping is at the firm level. (This mean is to be used as an instrumental variable for the width of all products in firm 1.)
So, the mean that I should find is: (25+15+40+10+35)/5=25
Then repeat the process for other firms.
firm prod width mean_desired
1 1 30 25
1 2 10 25
1 3 20 25
2 1 25
2 2 15
2 4 40
3 2 10
3 4 35
I guess my biggest difficulty is to exclude the own firm values.
This question is related to this page here: Calculating group mean/medians in MATLAB where group ID is in a separate column. But here, we do not exclude the own group.
p.s.: just out of curiosity if anyone works in economics, I am actually trying to construct Hausman or BLP instruments.
Here's a way that avoids loops, but may be memory-expensive. Let x denote your three-column data matrix.
m = bsxfun(#ne, x(:,1).', unique(x(:,1))); % or m = ~sparse(x(:,1), 1:size(x,1), true);
result = m*x(:,3);
result = result./sum(m,2);
This creates a zero-one matrix m such that each row of m multiplied by the width column of x (second line of code) gives the sum of other groups. m is built by comparing each entry in the firm column of x with the unique values of that column (first line). Then, dividing by the respective count of other groups (third line) gives the desired result.
If you need the results repeated as per the original firm column, use result(x(:,1))

How to group a column in tableau based on value of another column

I am new to tableau and need help in figuring this out.I have a dataset in below format:
hid:id for the house the customer belong
cid:customer id
hID CustomerID
1 A
1 B
1 C
2 D
2 E
3 F
3 G
3 H
3 I
4 J
5 K
5 L
5 M
5 N
5 O
So A,B belong to house 1 so count of hid '1' is 3 so:
hid count of members
1 3
2 2
3 3
4 1
5 5
I want to show a graph in tableau as size of house that is X-axis :Size of house and Y-axis :Count no of house with same size so for above data the values as below:
Size of house no of house
1 1
2 1
3 2
4 0
5 1
The final graph should be:
In Tableau jargon, you're looking to bin based upon an aggregate value. Take a look at the following blog post for a more detailed description/walk-through.
One way to accomplish this is by leveraging talbeau's level of detail calculations. Creating a calculated field along the lines of:
{FIXED [hID] : COUNTD([CustomerID])}
You can then create a bin field by right clicking on the new field and binning based on a parameter, or a a static size (1?) of your choosing.
To create the visual, place this second bin field on the row shelf and on the column shelf drag the hID dimension and right click to convert to a measure by selecting Count Distinct.
As a side note, depending on whether you set your bin field as continuous or discrete, the 4 bin in your sample data will or will not appear.

Running Total To Exclude Supressed Value in Crystal Reports

I wish to sum the data on display in my crystal report and not the suppressed data.
I have used the field editor and suppressed tool in the repeated area and I have the below formula for the rows to be suppressed:
{fieldname} = previous {fieldname}
I have read that if I use the running total and enter the opposite formula to subtotal then the subtotal will sum only the values displayed, e.g.
{fieldnmae} <> previous field-name.
However after doing this the first row is now totaling as the previous will be null. The report is sorted so the first row will always be a true value. Is there a formula I can use to display this to sub total? E.g. if Previous {filedname} isnull or {fieldname} <> previous field-name = sub total.
Or is there another solutions to this?
The data looks something like
Row No Value
0 20.00
0 20.00
1 25.00
2 10.00
3 7.50
4 5.00
4 5.00
If row no repeated than do no sub total or display
Many Thanks !!!!!
Chris
Easy way would be don't manipulate on Value column instead manipulate Row No column.
Create a running total and sum when Row No changes which will give correct results

Summing variable used in calculation after report is generated

I am creating a report where a query returns a list of values which are being used in my detail band. A new value shows for each record like it should. I'm trying to sum up these values and then use them in a calculation on the same line. Heres an example:
Color Fruit # of fruit Percent of total
--------------------------------------------------------
red apple 4 57%
green apple 3 43%
Total apples 7
The column being summed is the # of fruit or 3rd column. You can see the total at the end. Then the percent of total is the # of fruit for that row divided by the total. So for the first row it's 4 / 7 which equals 57%.
The problem is that I can't get the total until all the fruit has been summed. But I need that total to be used on each row for the Percent of total column.
How do I create a variable to do this?