Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

ssrs return latest 4th week

Not sure if this can be done, I have a report in SSRS (Report Builder 3).  
 
I currently have a parameter called 'First Week' which returns 07/04/14 as the first Monday of April (our week 1) and I have a parameter called 'LastWeekNo' which at the moment returns 16 as last weeks no.  I base most of our reports on whatever week number was last week (16 at the mo).


However some of my reports are monthly and are required to return the figures ONLY from the most recent 4th week , so for example the first 'monthly report' would have looked at our week 4, and kept looking at our week 4; until week 8, at which point it would then look at week 8, for 4 weeks, then it would change to week 12 and so on..

I'm sure there's a simple mathematical equation in there somewhere, but for the life of me I can't think of it!!  I need to create a parameter that returns that most recent '4th week'!  

Many thanks in advance!
0
deborahhowson00
Asked:
deborahhowson00
  • 4
  • 2
1 Solution
 
Harish VargheseProject LeaderCommented:
Can you give some examples? If you open the report today (7/29), what should be displayed as Week Number? Is that dependant on current month? or something else?
0
 
Harish VargheseProject LeaderCommented:
And what type of solution do you prefer - SSRS expression or SQL query?
0
 
deborahhowson00Author Commented:
Hi, if I opened the report today then the week number should be 16.  If I had opened the report last week then the week number should have been 12.  I don't mind ssrs or sql - both would be a bonus :)
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
Harish VargheseProject LeaderCommented:
Still not clear about the requirement. Is it that for any day in April, it should be 4; for May, 8; June - 12, July - 16, August - 20, September - 24, October - 28, November - 32, December - 36, January - 40, February - 44, March - 48?
If so, you may use below SQL:
select case when MONTH(getdate()) < 4 then (MONTH(getdate()) + 9) * 4 else (MONTH(getdate()) - 3) * 4 end

Open in new window

But all together there are 52 weeks in a year!!
0
 
deborahhowson00Author Commented:
Hi, thanks for your help so far.  No, we cannot look at figures in April because they don't exist till the end of April.  So in May we look at the last week April to get the month end figures, in June we look at the last week in May, etc.

So for our week nos, the last week in April is week 4, so for the whole of MAY's monthly report we should be looking at week 4.  Then when we get to June, the last week in May is week 8, so for the whole of JUNE's monthly report we should be looking at week 8.  The report itself states that it is for the May/June in the title, we can't have figures in the report for a month end that hasn't happened yet.  Hope that makes sense!
0
 
Harish VargheseProject LeaderCommented:
Then you can change it as below:
select case when MONTH(getdate()) < 5 then (MONTH(getdate()) + 8) * 4 else (MONTH(getdate()) - 4) * 4 end

Open in new window

And in case you need actual number of weeks (not just multiples of 4), you may use below script:
select case when MONTH(getdate()) < 5 then DateDiff(week,'04/01/' + cast(year(GetDate())-1 as varchar), DateAdd(dd, -Day(GetDate()), getdate())) 
	else DateDiff(week,'04/01/' + cast(year(GetDate()) as varchar), DateAdd(dd, -Day(GetDate()), getdate()))  end

Open in new window

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now