Solved

ssrs return latest 4th week

Posted on 2014-07-29
6
220 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
Comment Utility
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
Comment Utility
And what type of solution do you prefer - SSRS expression or SQL query?
0
 

Author Comment

by:deborahhowson00
Comment Utility
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 12

Expert Comment

by:Harish Varghese
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction As you'll probably know, a data region in a SQL Server Reporting Services report can be linked to only one dataset.  This makes it troublesome when you need to display data from more than one dataset in the same data region.  SQL Serve…
Hi All, I am here to write a simple article to move SSRS (SQL Server Reporting Services) reports from one server to another. When I have faced the same issue to move reports those were developed by developer on development server and now need to …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now