Solved

ssrs return latest 4th week

Posted on 2014-07-29
6
225 Views
Last Modified: 2014-09-02
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
Comment
Question by:deborahhowson00
[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
  • 4
  • 2
6 Comments
 
LVL 12

Expert Comment

by:Harish Varghese
ID: 40226166
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
 
LVL 12

Expert Comment

by:Harish Varghese
ID: 40226172
And what type of solution do you prefer - SSRS expression or SQL query?
0
 

Author Comment

by:deborahhowson00
ID: 40226280
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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 12

Expert Comment

by:Harish Varghese
ID: 40226361
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
 

Author Comment

by:deborahhowson00
ID: 40228620
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
 
LVL 12

Accepted Solution

by:
Harish Varghese earned 500 total points
ID: 40228733
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Written by Valentino Vranken. A while ago I wrote an article called Chart Optimization Tips (http://www.experts-exchange.com/articles/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Chart-Optimization-Tips.html).  This article explained how …
How to use Variables  and Custom code in SSRS report and Assembly reference to use compile shared code in SSRS. Its big question for all who are working with SSRS. It is easy to create assembly and refer in SSRS report, still there are some steps…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 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