crosstab report how to calculate specific columns values and subtract from row total - crystal-reports

am stuck at a point that in Crosstab report, i need to have sum of only two column's value and subtract the total by the value what should i do?
as in below,
Product 1 Product2 Product 3 Total
----------------------------------
Cust 1 4 5 2 11
Cust 2 5 9 7 19
I want to sum values of "Product 1","Product 3". then subtract from row total=> Total
LIKE
[4+2]-11=>TOtal.
and want to repeate this for each customer..
anyone please help me out.

I'm not sure when embedded summaries were introduced but I am pretty sure that your version of Crystal has this functionality. If not I apologize ahead of time. I have only been using this method for a few months now and it is quite confusing at first. At least to me but it has come in quite handy.....
I am making the following assumptions about your crosstab. Make name changes as you need to
row {yourtable.CustID}
Column {yourtable.product}
summarized field {yourtable.cost}
In the top left of your crosstab, right click go to advanced calculation and select calculated member
Select New and enter a description
For Type: Select Column
For insert Evaluation: Select After
Click edit insertion value and enter
CurrentColumnIndex=(GetNumColumns-2)//This will insert a column just before the total column
Click edit header formula and enter in quotes what you want to call the column
Select the content in Value Formulas then click Edit Value formula and number value
Save and close then exit the calculated member expert
Your crosstab should now have a new column
Right click the value go to Calculated member and select edit calculation formula
Enter this formula
(
GridValueAt (CurrentRowIndex,0 , 0) // Product 1 value
+
GridValueAt (CurrentRowIndex,2 , 0) // Product 2 value
)
-
GetTotalValueFor "yourtable.product")
NOTE: Geez it is hard to post on this site!

well after thinks long on it I've have done......
1st be clear that crystal report 10 is not offer following function
"CurrentRowIndex", "GridValueAt"
 
that's why above solution by "CoSpringsGuy" is not applicable.......
as we have two tables. 1 customer and 2nd for products and by both we generate crosstab with summarize field of product_sold (Qty) and 2 crosstab columns “Product.name”  and sub column product. Type
Now we want to sum value under the product.packing type =”Pilot”  of  product sold to each customer and subtract the sum-up from grand total of all products (product type “Normal” and “Pilot”)
For this problem 1st we have to work on formatting formula at crystal runtime and manipulate to “Display string” of summarize field
And then we will edit totals i.e very last column
1st edit summarize filed “display string” with the help of following code
Global CCust As String to keeping last customer for teli new customer name
Global Ccol As String ' tht is for keeping last column/product.packing type and teli with new col
Global Rndx as number ' this is for generating index of the row
Global totperx(22) as number ' is to hold the currnt value of cell and adding with previous value
' and i imagen that number of customers will less then 22 otherwise you can take unlimited array
Whileprintingrecords
if (CCust="") then
CCust=gridrowcolumnvalue("Table_Cust.Name")
Ccol=gridrowcolumnvalue("Viw_Prod.Packing")
Rndx=1
formula="new"
end if
if CCust<>gridrowcolumnvalue("Viw_Prod.Packing") then
formula="same"
Rndx=Rndx+1
else
formula="Newag"
end if
if Ccol<>gridrowcolumnvalue("Viw_Prod.Packing") then
Rndx=1
end if
if gridrowcolumnvalue("Viw_Prod.Packing")="Pilot" then
totperx(Rndx)=totperx(Rndx)+currentfieldvalue
end if
formula=totext(currentfieldvalue,0,"") ' despite of cstr function totext will change 45 to 45 while cstr changes 45 to 45.00
CCust=gridrowcolumnvalue("Table_Cust.Name")
Ccol=gridrowcolumnvalue("Viw_Prod.Packing")
now we will edit "Display String" of grand total column
Global my as number
Global totperx(22) as number
whileprintingrecords
if my<1 then
my=1
end if
formula=currentfieldvalue-totperx(my)
my=my+1

Related

Google Sheet: Pick max date out of row

Assume: in a google sheet the attendance to courses is logged with crosses.
Goal is to get the last attendance date of a person and add 6 months to it. ( course needs to be followed every six months ).
I've tried to retrieve the date of the last course in one column and add the +6months immediately and tried to have the +6 months in the second column, but I didn't succeed in both attempts.
See this link for example google sheet: https://docs.google.com/spreadsheets/d/10DG2I4VgTlOHJ5TG0qH4pJ5hJ9zsYuJCgRzEtuiTE60/edit?usp=sharing
=lookup("x",$B4:$F4,B$2:F$2)
Enter this formula in cell G4 and copy down the rows.
This formula looks for "x" (the attendance indicator) in cells in row 4 (columns B to F) - it's looking for the last instance. Then it returns the cell value from row 2 (the course date) of the relevant column.
=EDATE(G4, 6)
Enter this formula in cell H4, and copy down the rows.
This is pretty straightforward. It takes the date obtained from the lookup formula and adds 6 months.
Note that the lookup formula references column F. That's because as you create more courses you'll want the formula to automatically include them. So in cell F1, type something like "Don't use this column" - and then don't use that column!
Now when you add a new course, insert a new column to the left of the column headed "Don't use this column". This will ensure that the range in the lookup formula will expand to include the new column/course, and your latest attendance date will be updated automatically.
BTW, there's no guarantee that the date of the next course is a working day.

crystal reports sum only last item in detail

I wish to display in the group footer the sum of the sold qty column (which is easily done) and then only the last value of the on hand qty column.
I think a variable can do this, but not sure how to do it as I'm new to Crystal and its variables.
Here is an example
Sold qty On Hand Qty
details 1 5
2 3
============================================
GF Total 3 3
============================================
details 6 10
3 7
============================================
GF Total 9 7
Put the field {yourTable.OnHandQty} in the group-footer.
This will show the last detail value and will work as long as there's no suppression on details.
Note: The "last record" is determined by the sort within the group. This means that if the sorting is changed, the wrong value will be displayed.
Yes !! You can do this using variables.
Step 1: Create a Formula Field Named as OnHand
OnHand
shared numbervar OnHand;
Onhand := (Your Table Field) + Onhand +;
Place this one in Details section and suppress it (Right Click
Formula --> Format Field --> Common --> Supress)
Step 2 : Create one more formula to display the result
PrintOnHand
shared numbervar OnHand;
OnHand;
Place this formula in Group Footer
Step 3 : Create one more formula Clear
Clear
shared numbervar OnHand;
OnHand :=0;
Place this formula in group Header and suppress it. (This is to clear the Onhand
Value for every records or group).

Increment, display, and print a number of pages up to a Parameter maximum

I am trying to set up a Crystal Report to generate pallet labels which include a "Pallet N of M" line on each page.
The order in the database only has one entry, which contains all of the other information for the label(s). My issue is that the number of pallets isn't known until print time, and each label needs the same order information as well as a pallet ID. What I am looking for is for the user to enter a parameter for the total number of pallets, then have Crystal generate the correct number of unique labels.
For example, if the order has 4 pallets then Crystal should generate 4 copies of the label, the only difference on each copy being the last line which should read 'Pallet 1 of 4', 'Pallet 2 of 4', 'Pallet 3 of 4', and 'Pallet 4 of 4' respectively.
The only solution I can think of would be to create a number of sections equal to the maximum number of pallets, all containing my real data as a sub-report, then suppress any which are greater than the entered parameter. I am trying to avoid this because we may have greater than 50 pallets on a given order, so that would be tedious to create and is just not a very clean solution.
-= EDIT =-
Big thanks to Aliqux for the solution. In the end I needed to change the syntax to be Oracle compatible and also include the LINKVALUE field in the report, but the answer was 99% there especially considering I had not mentioned that my datasource was Oracle. The Command syntax I ended up using (with my parameter called TotalPallets) was:
SELECT
-1 AS "LINKVALUE"
FROM table
WHERE rownum <= {?TotalPallets}
You will need to Add a command to your tables.
1) Under database Expert in the Database you used select Add Command.
2) Click create to Create a Parameter.
3) Create the requested values, you can leave the Default Value blank if you want, and change the Value Type to Number. (I will be calling my parameter Counter)
4) Put the following in the SQL query where table is the main table you are using
SELECT TOP {?Counter}
-1 AS LINKVALUE
FROM table
5) Click okay and enter a value if prompted
6) In links link a number field, that will never go into negative numbers as we are using -1 for a base, to the LINKVALUE in the Command Table.
7)Link Options are as followed
Join Type: Inner Join, Enforce Join: Not Enforced, Link Type: !=
8) In your report create a formula with a shared numbervalue the starts from one.
shared numbervar counters;
if counters = {?Counter} then counters := 0;
counters := counters + 1
9) You can use that formula and the Counter Parameter for your labels
totext({#Counts},0,"")+" of "+totext({?Counter},0,"")
Credit reference: https://blogs.sap.com/2014/01/24/duplicating-data-details-records-n-times-eg-repeating-labels-n-times/

Crystal Reports 2 column crosstab

Using crosstab expert in CRpts, populating the columns selection with 2 column names and using preview, report has I cannot tell what is what. Report has helpdesk total by date and out of that total there is a group count for another dept. Report looks great with one column selected. However, once I select a column fr db and select it to the columns with Crosstab expert, the columns in the report preview are displayed but hard to tell what is what since I get No and Yes columns. I also have Keep Groups together, column totals on top, and Row totals on left "checked" out.
I want to be have: grand toatl column(for helpdesk) total for Dist. Classrooms afected totals
Can you help? I am also new to CR and have not been able to make a "hit" researching.
Based on the above, I want a report to look like:
(col 1) (col 2) (col 3
Date Group District Classes Affected
Crosstab expert has: 2 rows, 2 summaries(sum on date and grandtotal on top), 1 col(which works great with only col 2 used as column but not when I include col 3).
District is count of district's in group
Classes Affected is count of groups count.
Is this better?

how to do variable + 1 in iReport

i want to do line no in different band area. example, in group band i want it to appear
1.
2.
and the next band area, such as detail band, i want it continue
3.
4.
i dont it reset. how???
Create a group_COUNT variable. Make it an Integer, give it Calculation type Count, Reset type Report, Increment type Group and select the Increment Group. The Variable Expression should be $V{group_COUNT}++. Drop it to your Group zone and it should increment each time the group changes.
If you have created a group and you are using the detail band (means in detail band you have to print the valueis as you said ) then use the report generated variable like (your groupname_count) which gives the valuu like 123 and next band 3,4 as query found the records in the detail band.
or
if you have created the group and you have to print the nor as 1, 2 like this and for next group records 3,4
then create one variable class name is maths big decimal, calculation count, reset type your group nameincrement type none,variable expersion(in which the field which have alws value display) place there initial value expression is 0.