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
Solved

ssrs return latest 4th week

Posted on 2014-07-29
6
224 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
  • 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 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.

Question has a verified solution.

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

Have you ever had to extract data from a Microsoft SQL Server database and export it to an Excel file, but did not want to use a DTS package? The concept in this article is not new, but it is the answer and will also work on 64-bit SQL boxes.   …
It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

791 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