Print Page | Close Window

Total Detail lines only after the n-th detail

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22502
Printed Date: 26 Apr 2024 at 10:51pm


Topic: Total Detail lines only after the n-th detail
Posted By: its-a-wrap
Subject: Total Detail lines only after the n-th detail
Date Posted: 28 Nov 2017 at 9:00am
I cant figure out how to calculate the following. Total pcs of candy ignoring the first "n" rows.   

for example: n=2 so:

detail rows-----
row | name | pcs of candy
1     susan      5
2     ben        10
3     james      3
4     laura      1

REPORT FOOTER------
TOTAL PCS of Candy: 4


I have tried a number of things but all have given errors about run time calculations (or something similar).



Replies:
Posted By: Valert16
Date Posted: 21 Dec 2017 at 11:29pm
Create a formula that replicates the column 'pcs of candy' but returns zero if the row is less than the Nth.
A posible formula could be (VB syntax):

WhileReadingRecords
Global Counter as Number
If Counter + 1 > NthRow Then
    formula = {pcs_of_candy}
Else
    formula = 0
End If
Counter = Counter + 1

Replace NthRow with your value and {pcs_of_candy} with the exact name of the field. Place the formula in detail section and hide it.
Create a Summary field and choose the formula you've created as a field to summarize. You should get the correct total.


Posted By: its-a-wrap
Date Posted: 10 Jan 2018 at 3:48am
Thank you. This is similar to what I had tried previous to asking the question. It's a very simple problem, so i was surprised my efforts did not work until now. For some reason the crystal syntax or maybe missing the "WhileReadingRecords" caused it to not work. In any case, I figure I would share my code.

The actual problem was to charge customers a 4% fee only after the tenth order they've placed.


/////////////////////////////

WhileReadingRecords;

//How many orders are free
Global numberVar freeOrders;
freeOrders := 10;

//Fee percentage
Global numberVar orderFeePercentage;
orderFeePercentage := .04;

//Count number of orders so far and iterate++
Global numberVar rowCounter;
rowCounter := rowCounter + 1;

IF rowCounter > freeOrders
THEN {@salesLessDiscountsLessMisc}*orderFeePercentage
ELSE 0


Posted By: Valert16
Date Posted: 10 Jan 2018 at 5:14am
I forgot to mention I use Basic syntax, not Crystal.
May this help you?


Posted By: its-a-wrap
Date Posted: 19 Jan 2018 at 3:19am
It was helpful. But, i did also post the crystal syntax above to help other users in the future. Thank you.



Print Page | Close Window