?
Solved

ssrs return latest 4th week

Posted on 2014-07-29
6
Medium Priority
?
230 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 1500 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction: This article is aimed at report developers who are used to developing reports using relational databases and have gotten a first-time assignment to develop reports on OLAP cubes. It demonstrates how to build a report using SQL Ser…
Introduction Earlier I wrote an article about the new lookup functions (http://www.experts-exchange.com/A_3433.html) that ship with SQL Server 2008 R2.  In this article I’m going to show you another new feature of SSRS 2008 R2, this time in the vis…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

718 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