문제

I am calling the data query in ssrs like this:

SELECT * FROM [DATABASE].[dbo].[mytable]

So, the current week is the last week from the query (e.g. 3/31 - 4/4) and each number represents the week before until we have reached the 12 weeks prior to this week and display in a point chart.

How can I accomplish grouping all the visits for all locations by weeks and adding it to the chart?

도움이 되었습니까?

해결책

I suggest updating your SQL query to Group by a descending Dense_Rank of DatePart(Week,ARRIVED_DATE). In this example, I have one column for Visits because I couldn't tell which columns you were using to get your Visit count:

-- load some test data
if object_id('tempdb..#MyTable') is not null
drop table #MyTable
create table #MyTable(ARRIVED_DATE datetime,Visits int)
while (select count(*) from #MyTable) < 1000
    begin
        insert into #MyTable values
            (dateadd(day,round(rand()*100,0),'2014-01-01'),round(rand()*1000,0))
    end

-- Sum Visits by WeekNumber relative to today's WeekNumber
select
    dense_rank() over(order by datepart(week,ARRIVED_DATE) desc) [Week],
    sum(Visits) Visits
from #MyTable
where datepart(week,ARRIVED_DATE) >= datepart(week,getdate()) - 11
group by datepart(week,ARRIVED_DATE)
order by datepart(week,ARRIVED_DATE)

Let me know if I can provide any more detail to help you out.

다른 팁

You are going to want to do the grouping of the visits within SQL. You should be able to add a calculated column to your table which is something like WorkWeek and it should be calculated on the days difference from a certain day such as Sunday. This column will then by your X value rather than the date field you were using.

Here is a good article that goes into first day of week: First Day of Week

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top