I have a report in Crystal Reports 2013 that is grouping multiple transactions into an aggregate transaction by account number.
The value is Amount, so in the Group Footer is it listed as SumofAmount.
The field must be 17 characters long, so any number must be padded with leading zeros.
The values are assumed to be decimal, so they are all integers.
For example, the following transformations would occur:
3123 needs to be: 00000000000003123
23283792387 needs to be: 00000023283792387
If I right-click in Formula Workshop > Formatting Formulas > Group Footer #1 > SumofAmount I get a New Formatting Formulas which has leading zeros as an option, but how do I define this with a Boolean (this is a requirement)?
Right click on the field you need to have leading zeros.
select format field
select the common tab
select X2 to the right of Display String
Enter the following formula
right("000000000000000"&totext(CurrentFieldValue,"#"),15)
This assumes the total length of the field is 15. To change for your required length
change the number 15 to the desired length of the field
change the number of 0's between the quotes to at least the desired
length of the field
Repeat this for any field you need leading zeros
Related
I am trying to add two zero place holders in front of a field without changing the actual values involved. The field is an order number that is being pulled from MOMs. So right now that fields' formula is {cms.ORDERNO}.
When I try '00'+{cms.ORDERNO} the field displays 001,254.00. How can I remove the decimals and comma so it displays 001254?
The usual trick is to pad with plenty of extra digits on the left and then only take the six you really want from the right. This would handle any order number ranging from 1 to 999999.
right("000000" + totext({cms.ORDERNO}, "0"), 6)
When you don't specify a format string, as you tried, it uses default settings which usually come from Windows. By the way, if I recall correctly cstr() and totext() are equivalent for the most part but totext() has more options.
You should also be able to specify "000000" as the format string to produce the left-padded zeroes. Sadly I don't have Crystal Reports installed or I'd check it out for you to be sure. If this is the case then you probably don't need a formula if you just want to use the formatting options for the field on the canvas. If you do use a formula it's still simple.
totext({cms.ORDERNO}, "000000")
You definitely want to use the Replace formula a few times for this. The formula below converts ORDERNO into string, removes any commas and trailing decimal places, then adds the two zeroes at the beginning:
`00` + REPLACE(REPLACE(CSTR({cms.ORDERNO}),".00",""),",","")
So for example, if cms.ORDERNO is 1,254.00 the output from this formula would be 001254
I know this is older, but better solutions exists and I ran across this same issue. ToText has what you need built right in.
"00" + ToText({cms.ORDERNO}, 0, "")
From the Crystal Documentation:
ToText (x, y, z)
x is a Number or Currency value to be converted into a text string; it
can be a whole or fractional value.
y is a whole number indicating the number of decimal places to carry
the value in x to (This argument is optional.).
z is a single character text string indicating the character to be
used to separate thousands in x. Default is the character specified in
your International or Regional settings control panel. (This argument
is optional.)
I have two values: Value and Percentage. To calculate the total, I just need to create a formula like this one:
({table.value} / 100.00) * {table.percentage}
My report shows the amount of sales grouping by product:
Value----------Percent-----------Total
Sum of Value---???---Sum of the formula above
The problem starts when I need to show the percent value grouped by products, I can't simply show a Sum of Percent and showing the Medium displays wrong value.
*Correct total based on the percentual.
For example, the second line of the table shows values grouped by product, as you can see, simply calculating the Medium shows 6,34 when it should be showing 8,32.
So, I was thinking about creating another formula, just to calculate the Percent value when grouped, like this:
Sum ({#Calculated}, {product.product_id}) / Sum ({table.value}, {product.product_id}) * 100
When previewing, it shows the correct values, but when running, it throws an exception telling me that I can't Sum the {#Calculated} because it needs to be bound to a grouping.
Is there any way to recalculate the percentual value based on a formula?
I need to build a text field by stringing 2 numbers together for a barcode.
For example: fld1 is 12345678 and fld2 is 145.99.
fld1 needs to be 9 characters long, zero filled and fld2 needs to be 8 characters long, zero filled.
I need the string to be 01234567800014599
There is 2 step to do. One need concatenation, for this '+' is used to concatenate.
For the leading zero you can use Right function (refer below link)
ToText({table1.fld1},"000000000") + ToText({table1.fld1},"000000000")
or
Right("0000"&{table1.fld2},8) + Right("0000"&{table1.fld2},8)
just check this link :- Padding a fixed number with leading zeros up to a fixed length
Crystal report; Combining rows of data into a single value
I am trying to sum two different formula fields in Crystal. It will not let me select them from the Sum. The first formula is
if Sum ({tblPostedLine.pli_QUANTITY_SHIPPED}) >= 1
then {tblPostedLine.pli_NET_PRICE}
else ({tblPostedLine.pli_NET_PRICE} * -1)
I am trying to take a price and make it a negative value if the quantity is a negative value. I then want to sum the amounts to get a net amount that was shipped.
The other formula is
If PreviousIsNull({RodsvwCatalogAnalysis.pro_PROMOTION_CODE})
or ({RodsvwCatalogAnalysis.pro_PROMOTION_CODE}) <>
Previous({RodsvwCatalogAnalysis.pro_PROMOTION_CODE})
then {RodsvwCatalogAnalysis.pit_AREA_PER_PAGE} else 0
With this formula, I am trying to sum at a group level, not the details level. When I just sum the group level number, it is adding it every time the value is listed in the details as well.
I am open to any suggestions.
Thanks!
For the first scenario,
Create 1 variable formula in detail level to hold with your requirement.
for e.g.
#NetPrice , formula if {tblPostedLine.pli_QUANTITY_SHIPPED} >= 1 then
{tblPostedLine.pli_NET_PRICE} else ({tblPostedLine.pli_NET_PRICE} * -1)
using running total field feature in your Field Explorer to sum up the value and place
your group footer.
For the second scenario, I believe it relate to promotion group and again you could use the running total field feature to evaluate the sum condition and reset the value when condition are meet like field value change.
I am trying to create a formula field in Crystal Report XI that takes a monetary/numeric field and converts it to 10 characters with preceding zeroes, while dropping any commas or decimals. For example: 2,907.41 becomes 0000290741. Does anyone have any idea of how to do this?
totext(({table.number}*100),"0000000000")