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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Distinct count of uniquely created strings based on variables

Status
Not open for further replies.

DJWheezyWeez

Technical User
Jun 5, 2008
265
US
This is a strange issue that I feel like there is a solution to but I can't figure out how to do it.

In my main report, I have 4 different sub reports, each of them with a variable to hold some piece of information. In the main report, I have a formula that essentially creates one string by putting them all together, Var1 & Var2 & Var3 & Var4. What I'm trying to do is put some kind of text in GF1 alerting the user of multiple unique strings because they SHOULD be the same within each group but if not, this will cause a problem down the road.

My first thought was something like distinctcount({@CustomString}, {GroupOne}) but I'm unable to because {@CustomString} contains variables. Is there some way around using distinctcount while achieving the same result? Or something like a maximum({@CustomString}, {GroupOne}) and minimum({@CustomString}, {GroupOne}) then comparing the two (which also fails because of the variables)?

Any help would be greatly appreciated. Thanks.
 
I managed to find a way around my problem assigning a number value to each different option of each sub report variable. I'm sure there's another way to achieve the same result but this is the roundabout way I went about solving my problem. For anyone with this same problem, here's how I did it.

In sub report 1, I have a variable called G7 that can be either "G7" or "".
In sub report 2, I have a variable called ProofingSource that can be "ppr", "clr", "syn", "met", or "foam".
In sub report 3, I have a variable called InkType that can be "conv", "digital", "eb", "syn", or "uv".
In sub report 4, I have a variable called ScreeningCode that can be "am150", "am175", "am200", "fm2", "i175", or "o25".
These sub reports are all in the detail section, Da.
The following formula is in Db.
Code:
shared stringvar G7;
shared numbervar G7Number := 0;
shared numbervar G7Number := 
if G7 = "G7_"
then 1000
else 0;

shared stringvar ProofingSource;
shared numbervar ProofingSourceNumber := 0;
shared numbervar ProofingSourceNumber := 
if ProofingSource = "ppr"  then 100 else
if ProofingSource = "clr"  then 200 else
if ProofingSource = "syn"  then 300 else
if ProofingSource = "met"  then 400 else
if ProofingSource = "foam" then 500 else
0;

shared stringvar InkType;
shared numbervar InkTypeNumber := 0;
shared numbervar InkTypeNumber :=
if InkType = "conv"     then 10 else
if InkType = "digital"  then 20 else
if InkType = "eb"       then 30 else
if InkType = "syn"      then 40 else
if InkType = "uv"       then 50 else
0;

shared stringvar ScreeningCode;
shared numbervar ScreeningCodeNumber := 0;
shared numbervar ScreeningCodeNumber := 
if ScreeningCode = "am150" then 1 else
if ScreeningCode = "am175" then 2 else
if ScreeningCode = "am200" then 3 else
if ScreeningCode = "fm2"   then 4 else
if ScreeningCode = "i175"  then 5 else
if ScreeningCode = "o25"   then 6 else
0;

shared numbervar PressConditionSum := 
PressConditionSum + G7Number + ProofingSourceNumber + InkTypeNumber + ScreeningCodeNumber;

shared numbervar PressConditionNumber := 
G7Number + ProofingSourceNumber + InkTypeNumber + ScreeningCodeNumber
What the different pieces are doing is setting a number to the ones, tens, hundreds, and thousands place creating a unique number for each different string. For example, a created string might be G7_ppr_uv_am150 and this would have the number value of 1151 (1000 + 100 + 50 + 1). A different string would have a different number.

Next, I created another formula and put it in GF1, shown below:
Code:
shared numbervar PressConditionSum;
shared numbervar PressConditionNumber;

if (PressConditionSum/PressConditionNumber) - fix(PressConditionSum/PressConditionNumber) = 0
then ""
else "ERROR";
This formula takes the sum of all the numbers for all the strings in a group and divides it by the last string's number value then subtracts the number before the decimal. If there is no remainder, the formula shows nothing, but if there is a remainder, the formula shows "ERROR", telling the user that something is wrong. Reset formulas for PressConditionSum and PressConditionNumber were added to GH1.

There is a very small chance of an error with this. If there were three different strings where the values were 1111, 1131, and 1151, summing those together and dividing by 1131 would give you a whole number, without a decimal, and the formula would not show an error when you would want it to. In my specific case, this never comes up by the nature of the data, but to avoid something like this, try to sort the detail in such a way that the middle value would never show last in the detail.

Hopefully I've explained my solution in enough detail to help out someone else with a similar problem in the future.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top