Link to home
Start Free TrialLog in
Avatar of GStoner
GStoner

asked on

Cost difference over a 12 month period - if there are 12 months to compare.

Cost-Difference-Calculation-over-12-.pdfCrystal-Help.docxI’d like this report to calculate the cost difference over a 12 month period -  if there are 12 months to compare.  If there are not 12 versions, then I’d like it to display the cost difference  of the current version minus the cost of the oldest available version.

I've attached a pdf doc with more details on what I'm trying to do, existing formulas, as well as a screen shot of the current report.  
Please review the document and let me know if you have any ideas on how I can do this.
Avatar of Sharath S
Sharath S
Flag of United States of America image

There is no pdf attached. Pdf is hard to use. If you can provide sample data and expected result in an excel, that would be easy for any expert to help you.
Avatar of GStoner
GStoner

ASKER

Docs are attached now.
The attachments don't seem to be coming through correctly. As Sharath suggests, please post the sample data and expected results in Excel or any text format (i.e. not pictures). This allows the experts to copy and paste to create test cases.
Avatar of GStoner

ASKER

Not sure why the attachments aren't working for you.  Here is what I've been trying to share:

I’d like this report to calculate the cost difference over a 12 month period -  if there are 12 months to compare.  If there are not 12 versions, then I’d like it to display the cost difference   of the current version minus the cost of the oldest available version.
Example:
The highlighted numbers are version numbers.  It’s a 3 character field in our ERP, so the first charter is that last number in the year and the next to characters are the month.  

For the Stockton Elevation L1, 906 = 2019, June.  007 = 2020, July.  You can see that there are 12 versions and the formula for Cost Difference currently takes the current month version (007) minus the version that is 12 months old (906).
Elevations I1 and J1 are newer and do not have cost calculations older than version 005, so the Cost Difference formula does not calculate properly. It’s looking for version 906, which doesn’t exist, so it simply displays the 007 version minus 0.  
I’d like to add some logic that would look back 12 months and if that version doesn’t exist, use the oldest version that does exist, in this case 005.  So the Cost Difference for the Stockton I1 would be 142,598 – 144,907 = -2,309

User generated image
Here are how the current formula fields are built.
 Cost Difference:
 Sum ({@Version 1}, {hbs_plan.plan_id_})-Sum ({@Version 2}, {hbs_plan.plan_id_})
Version 1:
 
if {hbs_pvpo.version_} = {@thismonth} then {hbs_pvpo.cost_} else 0
Version 2:
 if {hbs_pvpo.version_} = {@Version Baseline} then {hbs_pvpo.cost_} else 0
Thismonth:
 
stringVar this:= "007";
Version Baseline:
 
stringVar last:= "906";

 I’m not sure how to modify the Version Baseline formula to look back 12 months / version and use oldest available version.
If 906 does not exist then use 907, 908, 909, 910, 911, etc. until it finds one with a value -  and then stop there and use that value.
In the example above for the Stockton Elevations I1, it would finde version 005 and use that cost value for the Cost Difference.
 (Version 007) 142,598 – (Version 005) 144,907 = -2,309
I’d be fine with having to revise the range of 12 monthly versions, as this is a monthly report that is used after we process monthly pricing changes.
Ideas?
What defines whether the data belongs to level I1, J1, or L1 (i.e. How did they get grouped that way)?
Avatar of GStoner

ASKER

I1, J1 and L1 are separate home elevations.  In this example, L1 has been in existence for for over 12 months, which is why there are 12 available versions for comparison (the 905 to 007 column).  Elevations I1 and J1 were created later and have only existed for the last three months (versions 005, 006 and 007).

So the Cost Difference formula in red works for L1, because I have it comparing the current version 007 minus the 12 month baseline version 906.

For elevations that don't have 12 months of historical data, I'd like the formula to be able to somehow use what is available - in this case 007 - 005.  How could I redefine what the baseline number would be?
If 906 doesn't exist, then use 907 or 908 or 909 or 910 or 911 or 912 or 001  or 002 or 003 or 004 or 005
and then have it stop and use 005 because it has a value.

Also if there are values for 006 and 007, which there are in this example, the baseline number needs to recognize the first version with a value, stop and use that number.  In this case 005.


That doesn't answer my question. I know that I1, J1, and L1 are different, but what makes them different?
For example, you have values for version 005 of $144,907, $148,234, and $153,031 but something, I assume in an underlying table, determines that $144,907 goes with level I1, $148,234 goes with J1, and $153,031 goes with L1. What is it that is "behind the scene" of your report that makes that determination?
Avatar of GStoner

ASKER

What makes them different is that they are separate elevations with unique elevation codes.
t1816i1 = Stockton Elevation I1
t1816j1 = Stockton Elevation J1
t1816l1 = Stockton Elevation L1

Each elevation is processed separately to calculate hard cost for each month, based on vendor pricing for materials.

User generated image
Avatar of GStoner

ASKER

Also, this example is just three elevations.  The full report contains about 100 different elevations.  Some have 12 months of historical data, some don't.  I need the Cost Difference to calculate the difference between the current month (007) and the baseline (906).  If 906 does not exist because there are non 12 months of historical data, then use the version that is availalbe.  In elevation I1 and J1, that would be 005.

For other elevations that could change.
Here's a different elevation that only has 8 individual months of data, so the Cost Difference needs to be able to calculate the difference between values 007 and 911, since the baseline 906 does not exist.
Avatar of GStoner

ASKER

User generated image
Okay, so we need a means of determining stringVar last when 12 months are not available. What does the code look like that creates the current report? I assume it's gathering data from the underlying tables. If so there should be a way of defining the earliest version so the stringVar last could be defined as the greater of the earliest version or the version 12 months prior to the current month.
Avatar of GStoner

ASKER

The data comes from our ERP system, so this particular report is using 5 tables that include dozens of fields.  The table that includes the processed versions (Example: 906 to 007) does include a process date field (prjv.process_date).

I just dropped it into the report so that you an see the the process dates for each version in the first column.
User generated image

Avatar of GStoner

ASKER

I may not be available until late this afternoon or tomorrow.  I appreciate any ideas you may have on how to use stringVar last.
I'm not very familiar with Crystal Reports but if you can set the stringVar last to the version where the process_date equals the min(process_date) or else the version that is 12 months prior, the problem should be solved.

ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GStoner

ASKER

I will try this later today or tomorrow and report back.
Avatar of GStoner

ASKER

This does exactly what I need it to do.  You've helped me several times in the past.  Once again, thank you for your help!
Avatar of GStoner

ASKER

One more question related to this solution.  
Following the solution, the Cost Difference calculates properly.  See report: Version Comparison - 12 MONTH PCA - Copy 2.pd

On the last page, I'd like to be able to show the average of the cost difference by Project ID, which is Group Header #1 and Group Footer #1.  The formula field "Display Difference" is not available to select for a running total formula.  Also, if I try to select that formula field and use Insert Summary, the field is not available to summarize.

I'd like to show the average of the Display Difference numbers in the project id / Group Footer #1 area.  See below. 

User generated image
See my comment in your other question

Crystal Reports - Summary formula is not available to use for averaging.
https://mail.google.com/mail/u/1/?tab=wm#category/updates/FMfcgxwJWrhMbSZTwPMPwvzGLNvbKHXs