• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 114
  • Last Modified:

convert week number to week ending date

I have a PO forecasting report.  I have a formula to give me the weeks as follows:

local NumberVar ThisWeek := datepart("WW",currentdate);
local NumberVar ThisYear := Year(currentDate);
if datepart("ww",{@Billing Date})=ThisWeek AND Year({@Billing Date}) = ThisYear then "Week 1"
else if datepart("ww",{@Billing Date}-7)=ThisWeek  AND Year({@Billing Date}-7) = ThisYear  then "Week 2"
else if datepart("ww",{@Billing Date}-14)=ThisWeek  AND Year({@Billing Date}-14) = ThisYear  then "Week 3"
else if datepart("ww",{@Billing Date}-21)=ThisWeek  AND Year({@Billing Date}-21) = ThisYear  then "Week 4"
else if datepart("ww",{@Billing Date}-28)=ThisWeek  AND Year({@Billing Date}-28) = ThisYear  then "Week 5"
else if datepart("ww",{@Billing Date}-35)=ThisWeek  AND Year({@Billing Date}-35) = ThisYear  then "Week 6"
else if datepart("ww",{@Billing Date}-42)=ThisWeek  AND Year({@Billing Date}-42) = ThisYear  then "Week 7"
else if datepart("ww",{@Billing Date}-49)=ThisWeek  AND Year({@Billing Date}-49) = ThisYear then "Week 8"
else if datepart("ww",{@Billing Date}-56)=ThisWeek  AND Year({@Billing Date}-56) = ThisYear  then "Week 9"
else if datepart("ww",{@Billing Date}-63)=ThisWeek  AND Year({@Billing Date}-63) = ThisYear  then "Week 10"
else if datepart("ww",{@Billing Date}-70)=ThisWeek  AND Year({@Billing Date}-70) = ThisYear  then "Week 11"
else if datepart("ww",{@Billing Date}-77)=ThisWeek  AND Year({@Billing Date}-77) = ThisYear  then "Week 12"
else if datepart("ww",{@Billing Date}-84)=ThisWeek  AND Year({@Billing Date}-84) = ThisYear  then "Week 13"
else if datepart("ww",{@Billing Date}-91)=ThisWeek  AND Year({@Billing Date}-91) = ThisYear  then "Week 14"
else if datepart("ww",{@Billing Date}-98)=ThisWeek  AND Year({@Billing Date}-98) = ThisYear then "Week 15"
else if datepart("ww",{@Billing Date}-105)=ThisWeek  AND Year({@Billing Date}-105) = ThisYear  then "Week 16"
else if datepart("ww",{@Billing Date}-112)=ThisWeek  AND Year({@Billing Date}-112) = ThisYear  then "Week 17"
else if datepart("ww",{@Billing Date}-119)=ThisWeek  AND Year({@Billing Date}-119) = ThisYear  then "Week 18"
else if datepart("ww",{@Billing Date}-126)=ThisWeek  AND Year({@Billing Date}-126) = ThisYear  then "Week 19"
else if datepart("ww",{@Billing Date}-133)=ThisWeek  AND Year({@Billing Date}-133) = ThisYear  then "Week 20"
else if datepart("ww",{@Billing Date}-140)=ThisWeek  AND Year({@Billing Date}-140) = ThisYear  then "Week 21"
else if datepart("ww",{@Billing Date}-147)=ThisWeek  AND Year({@Billing Date}-147) = ThisYear  then "Week 22"
else if datepart("ww",{@Billing Date}-154)=ThisWeek  AND Year({@Billing Date}-154) = ThisYear  then "Week 23"
else if datepart("ww",{@Billing Date}-161)=ThisWeek  AND Year({@Billing Date}-161) = ThisYear  then "Week 24"
else if datepart("ww",{@Billing Date}-168)=ThisWeek  AND Year({@Billing Date}-168) = ThisYear  then "Week 25"
else if datepart("ww",{@Billing Date}-175)=ThisWeek  AND Year({@Billing Date}-175) = ThisYear  then "Week 26"

And then I have a formula for each week that gives me the money sum amount for that week.  I need to put the week ending date for the title above each total instead of the wording Week 1, Week 2, etc.  I wrote the following formula which gives me the week ending date for week 1 but I can't get it to show in the report footer.  This is the formula...

if {@Week Breakdown} = "Week 1" then {@week ending date}

The @week breakdown is the first big formula listed.

Anyone have any suggestions?  Hope this makes sense.
0
lrollins
Asked:
lrollins
  • 10
  • 7
1 Solution
 
mlmccCommented:
Are you using a cross tab for this?

mlmcc
0
 
lrollinsIT ManagerAuthor Commented:
No I'm not using cross tabs
0
 
mlmccCommented:
I assume the big formula is Week Breakdown

What is the Week Ending Date formula?

Can you upload the report (even without data) so I can see what you are trying to do.

mlmcc
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
lrollinsIT ManagerAuthor Commented:
Yes the big one is the week breakdown.  The week ending is taking the billing date and giving the appropriate week ending date.

See attached.
PO_Forecast_26WK.rpt
0
 
James0628Commented:
A formula in the report footer is only going to see the values in the last record in the report.  {Week 1 Title} only displays something if PURCHASE_ORDER.DESIRED_RECV_DATE is in the right week, so if the date in the last record in the report is not in that week, {Week 1 Title} won't display anything.  A simple check would be to put DESIRED_RECV_DATE in the report footer and see if it's in "Week 1".

 Assuming that I'm right and the problem is that the date in the last record isn't in "Week 1", then the question becomes, what are you trying to do with {Week 1 Title} in the report footer?

 James
0
 
mlmccCommented:
You need to create a formula for each week or one that loads an array with the dates then formulas to display the dates from the array.

Try this idea - put these where you want to display the dates.

Week1Date
WhilePrintingRecords;
Global DateVar dtWeek1;
dtWeek1 := CurrentDate - DayOfWeek(CurrentDate);
dtWeek1 + 7

Open in new window


Week2Date
evaluateAfter({@Week1Date});
Global DateVar dtWeek1;
dtWeek1 + 7 *2

Open in new window


Week3Date
evaluateAfter({@Week1Date});
Global DateVar dtWeek1;
dtWeek1 + 7 * 3

Open in new window

...
Week26Date
evaluateAfter({@Week1Date});
Global DateVar dtWeek1;
dtWeek1 + 7 * 26

Open in new window


mlmcc
0
 
lrollinsIT ManagerAuthor Commented:
What I need is for the Titles at the end of the report to give me a week ending date instead of saying Week1, Week2, etc.   I want the week ending date based on the billing date.  I'll try your above formula and see if this works.
0
 
lrollinsIT ManagerAuthor Commented:
Current date won't work.  I have to base it off of the billing date.
0
 
mlmccCommented:
The labels won't change.  Week numbers are based on current date.

According to the formula Week 1 if run today is 23 Dec 2017, the other week dates are determined from that.

Which box the values go in are determined by the billing date but the dates for the weeks are based on today.

mlmcc
0
 
lrollinsIT ManagerAuthor Commented:
He doesn't always use the current date (sorry should have said that).  Some times he back dates like 8/1/2017 and that's a parameter box when the report is run.
0
 
mlmccCommented:
Ok.  So use the parameter value instead of current date.

Is the parameter optional?

mlmcc
0
 
lrollinsIT ManagerAuthor Commented:
I'm on vacation til January 2nd. I'll try this when I get back.
0
 
lrollinsIT ManagerAuthor Commented:
Using the Billing Date doesn't work either.  It gives me the current year calculated instead of using last year's date to calculate.  It's got to be sort of like the Week Breakdown formula.
0
 
mlmccCommented:
Try this as the week1 formula

Week1Date
WhilePrintingRecords;
Global DateVar dtWeek1;
dtWeek1 := CurrentDate - DayOfWeek({?Start Date});
dtWeek1 + 7

Open in new window


mlmcc
0
 
lrollinsIT ManagerAuthor Commented:
No that didn't work.  My ?Start Date is 8-1-17 and it returns dtWeek1 as 1/12/18.
0
 
mlmccCommented:
CurrentDate should be {?StartDate}

WhilePrintingRecords;
Global DateVar dtWeek1;
dtWeek1 := {?StartDate} - DayOfWeek({?Start Date});
dtWeek1 + 7

Open in new window


mlmcc
0
 
lrollinsIT ManagerAuthor Commented:
That worked.  Thanks
0
 
lrollinsIT ManagerAuthor Commented:
Thank you so much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 10
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now