Select if last 6 visits happened within 30 days - crystal-reports

Using Crystal 2013, my report groups by customer_id. The details are the times(datetime) that the customer has visited. I've figured out how to detect a minimum of 6 visits, but I am want to check if those 6 visits happened within 30 days.
I want to show all of the visits for the customer, but I want to only show the groups that meet the criteria. Do I need to do a Whileprintingrecords to do a datediff between the first and 6th record for each group? How can I do this?
Here is what I have:
30 >= DateDiff ("DD", (if {Command.ROW} = 1 then {Command.Visit_START},
(if {Command.ROW} = 6 then{Command.Visit_STOP}))

Are you able to sort the group in Descending order? I have an idea but it will be less work for you if they're grouped newest to oldest.
WhileReadingRecords:
In each group you'll need to determine the 1st and 6th visit. (You're currently suppressing any groups with less than 6.) To do this, I would make a Shared Variable called Counter that increments by one every record and resets every time it reaches a new group. (Set it to zero in the Group Header.)
Next you'll need two more Shared Variables called FirstDate and SixthDate. These populate with the date value if Counter equals one or six respectively. Just like Counter you'll reset these every time the group changes.
WhilePrintingRecords:
If everything works, you should now have the two dates values you need for calculations. Add an additional clause in your current Suppression formula:
....
AND
DateDiff("d", FirstDate, SixthDate)

Related

Suppress records in grouped section between first two and last records in Crystal Reports

First, I am using Crystal Reports 2011. I need to suppress records in a group that fall between the first two records and the last record. In other words I only want to see record number 1 and 2 and the last record. I can easily suppress records that are not the first two, but getting the last record to not be suppressed has me at a standstill. I am creating a report where we want to only show the first, last and next-to-last time we purchased items. Some items have been purchased many, many times. I have the report grouped by part number, then all the dates we purchased the part (and other data) are in the group details. I have tried using a running total count, where I simply suppress details that are not 1 or 2, but the last record count varies depending on how many times we have purchased the item, so I don't know what the last count number will be for each group to use it in the suppress formula. I have also tried with declaring a variable and increment the variable for each record, but end up with the same problem as using running total count. Anyone have a suggestion?
To clarify my question a little further, I am sorting the group by date, most recent date first. So record count 1 is the last time we purchased and record count 2 is the next-to-last time we purchased. So by using record count I can suppress records that are not 1 or 2. The problem comes when trying to figure out how to not suppress the last record (which is the first time we purchased). Below is a link to a pic of what my report looks like with nothing suppressed. For this part I would want to suppress all records except 1, 2 and 5. But again, the last count number will change per part number depending on how may times we have purchased the part.
Help is greatly appreciated!!!!
Report cropped image
Using Crystal syntax you can test on OnLastRecord which returns true if you are on the last record or false if not. Simply suppress accordingly.
EDIT:
As pointed out by jmears, the above won't work for multiple groups of differing products.
Instead you can add a running total field to count each record within the group, reset on change of group. Then suppress the details based on the running total not being 1 or 2 (for the first two records) and not equal to the total count of records for the group.
Here's an example suppression formula, where {#rt} is the running total count of records. It uses the Count function to return the total count for the group
not({#rt} = 1 or {#rt} = 2 or {#rt} = Count ({fieldToCount}, {GroupField}))

Compute rolling average across years while displaying data split by year

The dashboard in the linked workbook shows a table with sales split by year on the top. Below, there's a table with the rolling average of the last 4 weeks, including the current. It's set to show NULL if there are not enough data points. I'd like for it to compute the first January 2018 value based on the current week and 3 full weeks from the end of 2017. Carrying that concept forward, all NULLs from 2018 onward will be eliminated. The NULLs for the first 5 weeks of 2017 will be the only NULL values. The average should always be computed on a full 4 weeks (28 days) even when week 53 doesn't contain 7 days.
How can I write a calculation to achieve what's described above?
I've tried putting the WINDOW_AVG function inside a LOD, but that's not allowed. Furthermore, I've also tried using FIXED and even FIXED inside WINDOW_AVG.
Here's one of my attempts:
{FIXED [Week_int]:
WINDOW_AVG(SUM([Sales]), -4, 0)
}
It returns this error: "Error: Level of detail expressions cannot contain table calculations or the ATTR function"
Here's the data structure. It includes one value of Sales per day.
Basically I created a dummy data in Excel by creating dates (from 1-1-2017 to 2-2-2021) and filling some random values (unif dist *5000) against these.
I added Week[date] to columns and year[date] to rows as in your screenshot. I added sum(value) on the text marks card.
Thereafter, I added table calculation --> Moving average --> edited it for previous 4 values , next 0 values, (check current value if you want to include current record), then check Null if there are not enough values. (your requirement). --> click compute using -Specific Dimensions change the order of fields below - drag Year above than week (table across then down will also create the same view)
You should be able to get a view as desired.
Regarding your query on number of days in the week, Tableau caters it automatically if you have chosen it datepart.
Edit I verified this in Excel, the method is correctly working.
See, the average of first 28 values in Excel
and the view built in tableau:
Here's the corrected dashboard hosted on Tableau Public.

How can I deselect an entire group based on the value of one member of the group?

We have customers that order product on an annual basis. I have a report that needs to show only customers and related orders that have NOT placed an order in the current year. I filter all orders down to the current year and the year prior.
Right now, if a customer has orders for last year, I want them to show on the report, but once the customer places an order for the current year, I want both the current year order and the prior year orders to drop off the report.
Our salespeople use this report to manage the customers that need to be contacted in the current year. Once the report is empty, they are done for the year.
I know how to suppress the rows based on the value of a single member of the group, but suppressing them does not remove them from the summary calculations, so I need them to either disappear, or I need to be able to change all values to zero for that customer once they place a new order.
Thank You.
I created a running total field to trap the current year.
If Year(#Date)=2019 then 0 else Qty
When I put the formula into a qty formula, I get the "Summary has been specified for a non-recurring field"

Crystal reports - Can't filter on custom formula number field

Crystal reports don't let me use a custom count formula field to filter which transactions to show in a manager report.
I'm creating a Crystal report that team leaders are supposed to take out to see on how many occasions their employees have reported in sick. A record is only supposed to show if that person has reported in sick 6 or more times the last 12 months.
The report shows a record (a page) for each employee belonging to the managers organisational unit. Below the employee information is a subreport where I show the transactions from the salary/time system. Using select expert, I have filtered out the transactions that is supposed to show. I have then created a database field that count which day was 12 months back from today, and filtered so that only the transactions falling into this period shows.
My last problem is that I only want to show the record that has a minimum of 6 such transactions during the period. I created a formula field named #Antal ("amount" in Swedish) that simply counts the distinct number of dates in the "from"-date for the salary transactions I'm showing (since a change of law 2019-01-01 we needed to create a new transaction type, so some of the occasions after 2019 may have two transactions referring to one sick leave, thus I'm counting the first day of the period instead), DistinctCount ({P_LSTAT.P_SXXX06})
Now, the subreport has a new column with Antal (amount) that counts the amount of the desired salary transaction. I then try to use the selection formula to only show records where {#Antal} >= 6 but I get the following error:
This formula cannot be used because it must be evaluated later
Is there any other (better) way of doing this, or am I simply missing something?
For your selection based on {#Antal} >= 6 you need to use the group selection formula, not the record selection formula. Record selection is used to select records which meet the criteria before reading in the data. Group selection is used to filter out entire groups of records based on summarised values, after the records have been read in and the summaries calculated - which sounds like exactly what you need here.
The value of a Formula Field is out of scope when the Select Expert is evaluated.
There is no process for calculating the value of a Formula Field before it is printed within the section of the report it is placed. The Select Expert is evaluated prior to any section of the report being printed, so at this time all Formula Fields are effectively Nothing.

Ntile usage in microstrategy

I need to compare last year sales and current year sales based on quintile score and should divide all the customers into 1,2,3,4,5 buckets using NTILE function.
Also need to include 2 more columns(old,new) in the report.
Old indicates customers who comes under 1,2,3,4,5 buckets in previous year but not purchased in current year.
New indicates customers who comes under 1,2,3,4,5 buckets in current year but not purchased in previous year.
For this i have created two custom groups one for previous year and other for current year.
In each custom group i have created 5 filters for 1,2,3,4,5 buckets and in one custom group i have included one more filter for old and in another custom group i have included filter for new.
In report results old and new columns are missing and remaining 1,2,3,4,5 values are getting for previous and current year in form of matrix(6*6).