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!

How to calculate a running average off of a variable formula

Status
Not open for further replies.

gallobask

Technical User
Jun 25, 2009
48
US
I have several variables to get the first and last records of some fields. 1st pain score (numbervar first_score), 1st temperature (numbervar first_temp)etc...my reset formula for the variables is on change of patient header. I am told to calculate a running average for each record....like this:

Patient 1st pain av 1st temp av
Smith 0 97.80
Jones 4 99.60
Doe 0 97.40
Watson 4 97.90
Mayley 0 97.80

I have used the 3 formulas for a running count before - is there a similar way to get a running average? I am on version 8.5.

Thanks in advance!



 
Please show the actual content of the formulas you are currently using.

-LB
 
Here are the formulas:
Re-sets:
shared numbervar first_score:=0;
shared numbervar last_score:=0;
shared numbervar first_temp:=0;
shared numbervar last_temp:=0;

Get Variables:
whileprintingrecords;
shared numbervar first_score;
if {DOC_PAIN.PAS_SERIAL} = NthSmallest (1,{DOC_PAIN.PAS_SERIAL},{CASES.CASS_CODE} )
then first_score := {DOC_PAIN.PAS_SCORE}

whileprintingrecords;
shared numbervar last_score;
if {DOC_PAIN.PAS_SERIAL} = Nthlargest (1,{DOC_PAIN.PAS_SERIAL},{CASES.CASS_CODE} )
then last_score := {DOC_PAIN.PAS_SCORE}

whileprintingrecords;
shared numbervar first_temp;
if {DOC_CARDIO.CARD_SERIAL} = NthSmallest (1,{DOC_CARDIO.CARD_SERIAL},{CASES.CASS_CODE} )
then first_temp := {DOC_CARDIO.CARD_TEMP}

whileprintingrecords;
shared numbervar last_temp;
if {DOC_CARDIO.CARD_SERIAL} = Nthlargest (1,{DOC_CARDIO.CARD_SERIAL},{CASES.CASS_CODE} )
then last_temp := {DOC_CARDIO.CARD_TEMP}


Thanks!
 
This is doable, but I'm wondering why you would want a running average of temperature and pain ACROSS patients--shouldn't this be within patient across a period of time?

-LB
 
This is for quality initiatives for our anesthesia department - they want to see improvement over time. Patients should enter the recovery room with lower pain scores and higher temperatures. If certain medications are started too soon in the procedure patients enter recovery room with high pain levels on awakening - they want to see these pain scores drop. Patients loose body heat during surgery and can enter recovery room hypothermic. So they want to see an upward trend in temps.
 
Okay, sorry for second-quessing you. However, I am still unclear. Your example shows only the 1st pain and the 1st temp, while your formulas are showing first and last for each. When you talk about the running average, what is it a running average of? Are you looking for some kind of average temp per patient across detail records that then contributes to a running average across patients?

It sounds like you have been instructed to provide this report. Please ask whether they want an average pain and average temp per person and then an average across patients (versus an average of first pain and an average of first temp across patients).

-LB
 
No Problem. Believe me I asked plenty questions myself to understand what they wanted...
They want an average across patients not per patient (Each patient will only have one 1st temp, one 1st pain score etc.). The records will be sorted by date so they will see a trend over time. Currently they only want to see 1st pain and 1st temp, but I am sure once they get the data they will want the others as well so I thought I should just include it all...

So....this is what they want to see...
1st pain av
5/1/2011 Smith 5 5
5/1/2011 Jones 2 3.5
5/2/2011 Doe 4 3.6
5/2/2011 Mayle 3 3.5
5/3/2011 Brown 3 3.4
Over a months time there will be over a thousand records...
 
Okay, then create these formulas (you don't need to use shared variables unless your values are coming from subreports). You also don't need variables for the nthlargest and smallest values or conditional formulas to get them.

//{@resetpt} to be placed in the report header or higher order group if the running average needs to be reset for something like dept:
whileprintingrecords;
numbervar cnt;
numbervar sumpain;
if not inrepeatedgroupheader then (
cnt := 0;
sumpain := 0
);

//{@running ave} to be placed in the (patient) cass_code group footer section:
whileprintingrecords;
numbervar cnt;
numbervar sumpain;
sumpain := sumpain + NthSmallest (1,{DOC_PAIN.PAS_SERIAL},{CASES.CASS_CODE});
sumpain/cnt

Repeat for temp, using different variable names for sumpain and cnt.

-LB
 
When I put the running average formula in the cass_code footer I get a message saying "Division by zero". Zero is an actual pain score so there is no way to get rid of them.
 
The error means that the count can be 0, that there are group instances with no records.

whileprintingrecords;
numbervar cnt;
numbervar sumpain;
sumpain := sumpain + NthSmallest (1,{DOC_PAIN.PAS_SERIAL},{CASES.CASS_CODE});
if cnt = 0 then
0 else
sumpain/cnt

This would return 0 if cnt = 0.

Maybe you need to check the placement of the formulas.

-LB
 
Now the formula displays 0.00 for all records. There is a pain score in each case footer record and there are no suppressions - so I don't know where the "no records" comes in. I've tried moving the reset formula with the same results. Not sure what else to try.
 
Please explain your group structure--what fields you are grouping on, and then explain where you have placed each formula.

-LB
 
3 Groups
1. Site (main hospital or surgery center)
2. Surgery Date
3. Case Code - the unique identifier of a patients surgery visit.

Variables to get the first and last pain scores and temps: reset is in the case group header, the "get" formula is in the details and the "show" formula and all of the other case info is in the case footer.

Vital signs like temp and pain scores can be logged in several what we call care events. There is preop (before surgery) intraop (during surgery) and post op (after surgery in recovery room) At the report level the care event selected is post op.

 
I am asking where you placed MY suggested formulas.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top