Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difficulty summing a value with a formula attached 1

Status
Not open for further replies.

ella38

IS-IT--Management
Nov 29, 2010
8
CA
HI, I am having difficulty when trying perform a summation on a field in the group footer that has formulas attached.
Here is the specifics,
There are 2 formulas.
1. Changes the decimal places of the current quantity
2. Attaches a unit value to the curretn quantity ( the 2nd formula points to the 1st formula)

When I try to perform a sum on the second formula to try and achieve a sum the current quantities. It gives me an incorrect number for the current quantity.
 
Please show the contents of the actual formulas to receive meaningful assistance.
 
Formula 1 = @CurrentEnrtyQtyDecimals
Local NumberVar NumPlaces := 10;
Local BooleanVar CheckPlaces := true;

While CheckPlaces Do
(

IF (NumPlaces > 0) AND (Val(ToText({A_B.QUANTITY}, NumPlaces, "")) - Val(ToText({A_B.QUANTITY}, NumPlaces - 1, "")) = 0)
THEN (NumPlaces := NumPlaces - 1;
CheckPlaces := true;)
ELSE (NumPlaces := NumPlaces;
CheckPlaces := false;)
);
NumPlaces

Formula 2 = @CurrentEnrtyQtyUnits

StringVar QuanityWithUnits := ToText ({A_B.QUANTITY}, {@CurrentEnrtyQtyDecimals});

IF IsNull({A_B.UNITS}) THEN QuanityWithUnits
ELSE IF IsNull({UNITS.DISPLAY_STRING}) THEN QuanityWithUnits + " " + {A_B.UNITS}
ELSE QuanityWithUnits + " " + {UNITS.DISPLAY_STRING}


Note: I am trying to sum @CurrentEnrtyQtyUnits
with these formulas attached
 
Ella,

At a glance I would suggest that you are trying to sum a field which returns a string. A running total designed the same as your second formula but without concatenating the units identifier may be a place to start.

I wasn't entirely sure what your first formula is truely achieving though, returning the number of decimal places? Clearly late in the day for me, my apologies for not being of more assistance.

Hope this helps,

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
If I perform a sum on A_B.Quantity, it works great except when I try to attach a unit to it. Without the sum I can attach the units and all is well.
The first formula was to remove the decimal places.

Any thoughts?
 
Ella,

Thanks for the clarification. =)

If you were using it to get a whole number in your summary, I think you need just create the following:
(this assumes report-level summary of Quantity, if a group summary, replace SUM({A_B.QUANTITY}) with the group summary)
Code:
IF IsNull({A_B.UNITS}) THEN ToText(SUM({A_B.QUANTITY}),"00") ELSE 
IF IsNull({UNITS.DISPLAY_STRING}) THEN ToText(SUM({A_B.QUANTITY}),"00") & " " & {A_B.UNITS} ELSE
ToText(SUM({A_B.QUANTITY}),"00") & " " & {UNITS.DISPLAY_STRING}

If your data contains decimal values in quantity you wish to round down first, create a fomula:
Code:
 Int({A_B.QUANTITY})
and summarize this formula in place of {A_B.QUANTITY}.

Hope this helps!

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
Unfortunately I tried the first formula and it is behaving in the same way as before. That is, it performs a sum of the first entries in the group and then carries the same value as the sum for all the other entries. Without applying a formula to attasch the units and keep the number as a whole number, the sum works on all the individual entries. The problem occurs when you try to format the sum with units and rmeoving the decimal.
 
If the sum is per some group instance, then you need to add the group condition. You can use int() as Mike pointed out to show whole numbers, and if you use "&", you do not have to convert values to the same datatype. So you should be able to use:

int(sum({A_B.quantity},{table.groupfield})) & " " & {UNITS.DISPLAY_STRING}

-LB


 
Thanks for your help!
I tried the code:
int(sum({A_B.quantity},{table.groupfield})) & " " & {UNITS.DISPLAY_STRING}
I am now able to get the correct sum with the units attached but there are still decimal places. ie. 13.00, I would like it to be 13.
 
You can set the decimals by formatting totext:

totext(int(sum({A_B.quantity},{table.groupfield})),2) & " " & {UNITS.DISPLAY_STRING} //2 for two decimals

-LB
 
Sorry, that should be:

totext(int(sum({A_B.quantity},{table.groupfield})),0) & " " & {UNITS.DISPLAY_STRING}//0 for zero decimals

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top