Distinct count not giving expected result - crystal-reports

I have fields for customer names, customer account numbers, date of previous orders, and order values. I want an alert to show which customers have ordered at least three times over the reporting period. We can have more than one invoice for a given delivery. The main report looks like:
Account Number Acct Name Order Date Order Total
1001 Fred Smith 1/2/2016 £1.06
1001 Fred Smith 1/2/2016 £2.34
1001 Fred Smith 8/2/2016 £5.42
2001 Aled Jones 1/2/2016 £2.90
2001 Aled Jones 8/2/2016 £3.45
I've tried concatenating the account number and order date in a column via function and running an alert based on its distinct count. (After converting the date to a string.) But it still doesn't generate a list of distinct items.
What I currently have in the final column is a function that concatenates the date and account number to give a unique field with {ORDR.CardCode} + Cstr({ORDR.DocDate}) - Which returns:
1001 1/2/2016
1001 1/2/2016
1001 8/2/2016
2001 1/2/2016
2001 8/2/2016
I want to generate alert based on this field via the distinct count function and a report of any customer who ordered at least twice in the report period.
DistinctCount ({#Concat code and date}) >2
Even after this I still don't get what I need. How can I get a list of every customer who has ordered in the report period for at least two times?

You have travelled half way... to achive continue from here.
USe the created formula {ORDR.CardCode} + Cstr({ORDR.DocDate}) to create a group.
place same formula in details and take count of the records in group footer
Now create a alert on group footer summation to get the desired result
Edit........
Since you need customer then add customer in concat fornula and then create group.
acctnamr+{ORDR.CardCode} + Cstr({ORDR.DocDate})
Now place the customer name in group header and follow process as explained above

Related

Group by date and calculate

For each account I need to subtract the earliest amount from the most recent amount.
Input
- ACCOUNT DATE AMOUNT
- 123 7/18/2017 500
- 456 7/18/2017 450
- 123 7/17/2017 300
- 456 7/17/2017 200
Desired output:
- 123 7/17/2017 7/18/2017 200
- 456 7/17/2017 7/18/2017 250
I've tried grouping by max and min dates, but it wasn't helpful. And I don't have much flexibility in regards to the sort of the input. How can I arrange the data properly?
Here's how I would do it:
Group by Account in ascending order.
Inside that group, Group by Date in ascending order.
Suppress all Group Headers/Footers and Details Section except for Account Group's Footer. This is where you will place all the fields you want to display.
Use 2 Shared Variables, FirstDate and FirstAmount. Set these up to store the first Date and Amount values that appear in each Account Group. (Use a Running Total that resets when this group changes. When it equals 1, fill the variables.)
In Account's Group Footer, make two formula fields:
Displays FirstDate & " " & Date
Displays Amount - FirstAmount

MSSQL Running IN OUT count Record

I'm trying to create a report that counts how many people are signed into a section or signed out of a section each day.
select inout.name_id, nametable.name, inout.datetime, inout.status, inout.section
from inout
join nametable on inout.name_id = nametable.name_id
where inout.date between '1/1/2016' and '1/3/2016'
order by inout.date
Sample Data:
Datetime Name Section Status
1/1/2016 1:34:56 John A IN
1/1/2016 4:11:11 Steve A OUT
1/1/2016 18:20:20 Bill A IN
1/2/2016 13:13:13 John A OUT
1/2/2016 12:12:12 Ben A IN
1/3/2016 1:01:01 JIM A IN
Then final result:
Date # of people in section
1/1/2016 2
1/2/2016 2
1/3/2016 3
EDIT: Was thinking IN status would give +1 to a running count and OUT would give -1, so if a person came into work or left work for the day i could see how many people are working in a specific section each day, I'm not quite sure how to show for the people that were there before that date range either though.
This is not an answer, but may help others to visualize and may inspire you (but i think you did try it):
Use the query you have posted.
In Crystal designer, create a group by the column 'Datetime'.
Create a formula: if {inout.status} = "IN" then 1 else -1. Let's say it's name is #Quantifier.
Create a running total field: field to summarize = #Quantifier, type of summary = sum, evaluate for each record, reset never. Let's call it #NumberOfPeopleInSection_CloseButNoCigar.
Put the running total field in the group footer.
The result, as you said you expected, is not really what you want, because there is this "Steve out" without a previous "Steve in". So it still needs a trick.
To turn it in a solution, you may try another query to get the initial count. Try something to:
select sum(case when status='IN' then 1 else -1 end)
from inout
join nametable on inout.name_id = nametable.name_id
where inout.datetime < '2016-1-1'
Then consider this initial value in the final result.

Group items based on a formula

I am creating an invoice using Crystal Reports & I want to group products which have the same PRO_ID into one line, for this I have created a GROUP and it works fine.
Following is a sample of the data
PRO_ID NAME ORDER_QTY
0001 Battery 2
0001 Battery -6
0001 Battery 3
In the second line the quantity is a minus because of a returned item. I want to show the actually ordered items separately & returned items separately.
At the moment the report shows -1 for the ORDER_QTY because it just groups the Products based on the PRO_ID. How can I group these separately ?
try this:
Keep PRO_ID as it is as the first group and then create a sub group #group2 and write below code:
if ORDER_QTY<0
then "Returned"
else "Actual"
Use #group2 to group after PRO_ID.
Now place the all your fields in details.
hope this helps

Tableau Number of days since last invoice

I have Tableau data which consists of Customer Name and Invoice Date.
Cust 1 - 01/01/2014
Cust 1 - 05/01/2014
Cust 2 - 10/02/2014
Cust 2 - 20/03/2014
etc.
I want to find the number of days since the last invoice for each customer and display the data in a table as follows:
Customer | # of days since last invoice
Cust 1 | 170 days
Cust 2 | 110 days
Once you have the customer field in the rows shelf,
Create a calculated field like this
DATEDIFF('day',MAX([InvoiceDate]),NOW())
Drag this calculated field to the TEXT mark.

Crystal reports - how to handle null while using group

I would like to know which is the best way to include null values in the report while using the below groups. My below report uses two groups one below other, Month group is under the field group. I have given the formula for the Field Group A; and for for the month I have used options to fetch the months from the specific date field [source is excel file] in ascending order. Since there are no data for group A - 1 records for October month I don't see any data whereas I would want to show the month with NA as result.
Report looks like below currently
Field GROUP -A - 1
Month Result
11-2012 xxx
12-2012 xxx
Field Group A- 0
Month Result
10-2012 xxx
11-2012 XXX
12-2012 xxx
But I would like the report to be as below:
Field GROUP -A - 1
Month Result
10-2012 NA
11-2012 xxx
12-2012 xxx
Field Group A- 0
Month Result
10-2012 xxx
11-2012 XXX
12-2012 xxx
Any suggestions will be helpful
Crystal Reports can't show the data, because there isn't any data to show.
There's only one instance I'm aware of where Crystal Reports will auto-fill NULL data, and that's when using a crosstab, which really doesn't appear to fit your needs or desired output.
You'll have to supply the "N/A" value for 10-2012, Group 1 in your query, possibly by using some table of dates to outer join against.