Solved

Median value

Posted on 2008-10-09
13
293 Views
Last Modified: 2012-05-05
I have a Running Total field in a Group Footer. I would like to get the Median value of those Running Totals in the Report Footer. Unfortunately, I am not offered the Group Running Total as one of the possible fields to summarize in another Running Total field.

Any ideas?
0
Comment
Question by:bt0011
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 2
13 Comments
 
LVL 17

Expert Comment

by:MIKE
ID: 22682439
Replace the Running TOTAL with a VARIABLE that will do the exact same thing. They use the VARIABLE to obtain the Median Value.

M
0
 

Author Comment

by:bt0011
ID: 22682569
I think I've already done that. To be clear, this report has multiple records which I use Running Total fields to add up in the Group Footer. I have a Variable in the Group Footer which sums two Running Total fields but this Variable does not appear as a field to summarize in the Report Footer.

or

are you saying I should replace the Running Total fields in the Group Footer with Variables?
0
 
LVL 17

Expert Comment

by:MIKE
ID: 22682593


.... "....are you saying I should replace the Running Total fields in the Group Footer with Variables ...."

YES...that is what I'm saying...then the VARIABLE that is displayed...wherever can be used to calculate the MEDIAN Value at any given point in the report....GROUP FOOTER ...AND/OR...REPORT FOOTER...

M
0
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

 
LVL 100

Expert Comment

by:mlmcc
ID: 22682825
You can't use the summary functions on variables or on running totals.

You can use a summary function on a formula but a formula that calculates the sum of 2 running totals is evaluated after all summary functiions are done.

You will have to develop a set of formulas to do the median.

In the report header add a formula
WhilePrintingRecords;
Global NumberVar Array GroupTotals;
Global NumberVar GroupCount;

In the group footer add a formula
WhilePrintingRecords;
Global NumberVar Array GroupTotals;
Global NumberVar GroupCount;
GroupCount := GroupCount + 1;
Redim Preserve GroupTotals[GroupCount];
GroupTotals[GroupCount] := {RTotal1} + {RTotal2};

Local NumberVar i;
Local NumberVar Temp;
For i := 1 to GroupCount - 1 do
    If GroupTotals[i] > GroupTotals[i+1] then
    (
        Temp := GroupTotals[i];
        GroupTotals[i] := GroupTotals[i+1];
        GroupTotals[i+1] := Temp;
    );
''

In the report footer
WhilePrintingRecords;
Global NumberVar Array GroupTotals;
Global NumberVar GroupCount;
If GroupCount mod 2 = 1 then
    GroupTotals[(GroupCount+1)/2]
else
    (GroupCount[GroupCount/2] + GroupTotals[(GroupCount/2) + 1]) / 2

mlmcc
0
 

Author Comment

by:bt0011
ID: 22683282
That is not working either... Perhaps because trying to do a Running Total Median is a 2nd pass operation which, per the Help, isn't supported. Is there a way to do the Median against to Group variable manually?
0
 

Author Comment

by:bt0011
ID: 22683292
Sorry, did not see MLMCC's response before my last post, I will give that a try. Thanks
0
 

Author Comment

by:bt0011
ID: 22711159
OK!! This is very close to working (Whew!!)  Just couple of minor things

First, in the Report Footer formula I had to change this:

(GroupCount[GroupCount/2]  

to this (

GroupTotals[(GroupCount/2] No big deal...

Now I have just one more minor problem... It seems that the wrong array values are being used, For example, when I have 10 values I get the quotient of the 6th and 7th value  / 2 instead of the 5th and 6th value. If I change to 9 values, I get the 6th value instead of the 5th value.

Seems like the array is being populated with a one place offset since the retrival formula in the Report Footer look like they are set to get the right slots...

I've tried to figure this out on my own ( obviously not well...) but I cannot see where
the problem is.

Thank you for all your help so far. It's been a real lifeline!
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 22711454
Can you copy and paste your formulas?

mlmcc
0
 

Author Comment

by:bt0011
ID: 22711588
Report Header:

WhilePrintingRecords;
Global NumberVar Array GroupTotals;
Global NumberVar GroupCount;


Group Footer:

WhilePrintingRecords;
Global NumberVar Array GroupTotals;
Global NumberVar GroupCount;
GroupCount := GroupCount + 1;
Redim Preserve GroupTotals[GroupCount];
GroupTotals[GroupCount] := {#RTotal0} + {#RTotal1};
Local NumberVar i;
Local NumberVar Temp;
For i := 1 to GroupCount - 1 do

    If GroupTotals[i] > GroupTotals[i+1] then

    (
        Temp := GroupTotals[i];
        GroupTotals[i] := GroupTotals[i+1];
        GroupTotals[i+1] := Temp;
    );

''


Report Footer:

WhilePrintingRecords;
Global NumberVar Array GroupTotals;
Global NumberVar GroupCount;
If GroupCount mod 2 = 1 then
    GroupTotals[(GroupCount+1)/2]
else
    (GroupTotals[GroupCount/2] + GroupTotals[(GroupCount/2) + 1]) / 2
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 250 total points
ID: 22711616
The problem is the insertion sort.  Try this one

WhilePrintingRecords;
Global NumberVar Array GroupTotals;
Global NumberVar GroupCount;
Local NumberVar NewValue :=  {RTotal1} + {RTotal2};
GroupCount := GroupCount + 1;
Redim Preserve GroupTotals[GroupCount];

Local NumberVar i;
i := GroupCount -1;
While  (i > 0) AND (GroupTotals[i] > NewValue) do
(
    GroupTotals[i+1] := GroupTotals[i];
    i := i -1;
);
GroupTotals[i+1] := NewValue;
''

mlmcc
0
 

Author Comment

by:bt0011
ID: 22712748
That works beautifully!!!

Thank you!!!
0
 

Author Closing Comment

by:bt0011
ID: 31504810
Thank you!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Crystal reports - finding a hidden reference 4 83
Store total calculated duration sessions. 44 98
Crystal Reports - group header 2 54
Crystal Report - Charts 4 32
Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question