SSRS matrix group by error - sql-server

I have an ssrs matrix with total in rows and months as columns .. something like this .
Jan Feb March
Total1
Total2
I can choose a month as a parameter and my matrix shows the results for the month and the two months before the current month.
When I choose August :
I can see June July August
When I choose September :
I can see July August September
But when I choose October
I see October August September
My client wants to see it as August September October
I don't know the reason for this behavior .But can anyone help me with this ??
I tried doing the sort for the tablix as follows :
=(Fields!Month.Value)
Month is a number like 1 for Jan, 2 for Feb. I add it as a sorting expression but I dont see any change in the sorting.

according to your data.
August = "8"
September "9"
October = "10"
it looks to me like you need to convert your month to an integer type, Sort is picking up your month as a string value.
try converting your month field to an integer in your sort expression and then running rerunning the report.
something like:
=CInt(Fields!Month.Value)

I finally found what was going wrong with my solution .
I was adding the sorting on the "tablix properties" section .
Sorting needs to be added on the "Column group" and not on the "tablix properties" and this did the trick in my case. :-)

Related

SSRS - Add year to month

In my report, i show the sales commission for 3 months from each sales person. I've also added the payout month. For a better overall look, i want to add the year to the payout month.
This is the month in my SQL-Query :
,[Monat] = convert(varchar(4),Year(Datum)) + right('00' + convert(varchar(2),Month(Datum)),2)
Right now, the expression for my payout month is this:
=MONTHNAME(IIF(RIGHT(Fields!Monat.Value,2)+2>=13,RIGHT(Fields!Monat.Value,2)-12+2,RIGHT(Fields!Monat.Value,2)+2))
The payout is always two months in the future. Commission of december 2020 will be payed in february 2021, january 2021 will be payed in march 2021 and so on.
I want the result to look like this:
Februar 2021,
März 2021
etc.
Is there a way to depict that in the SSRS expression? Thanks in advance.
If you just need to display the month and year from a date field after you have added 2 months to it, then you can just do something like this.
=DATEADD(DateInterval.Month, 2, Fields!Datum.Value)
You can then format the textbox using MMMM yyyy to display it as you want.
Alternatively, you can do it all in a single step but this should be avoided if possible as you are then losing the date and converting to a string. If you exported to excel for example, you would not be able to do anything with the cell as it would just be a string.
If you really have to do this in all in a single expression then you can use
=FORMAT(DATEADD(DateInterval.Month, 2, Fields!Datum.Value), "MMMM yyyy")

Dynamically filter the date by 6 months from today

I basically want to be able to dynamically filter out my chart to display data for the last 6 months. For example, it would show Jan 2019 to June 2019 and in July it would show between Feb 2019 to July 2019
Presently, I'm using filters. I was thinking of creating a calculated field for the 6 months but there are no functions to help me play with dates.
In the date-picker options, choose the one at the very bottom of the list which is called Advanced. Click on the end date option and where it says 'fixed' click and choose today. Do the same for the start date and you get the option to enter your conditions, which in this case would be today minus 6 months

Extended calendar which runs on 1st business day of 3rd of every month in autosys

I need to create extended calendar which will run on 1st business day of 3rd week of every month.
Mon to Fri are considered as working day and no holiday calendar included.
Sample dates for year 2018 :
16th Jan, 13th Feb, 13th Mar, 17th Apr, 15th May, 12th Jun, 17th Jul, 14th Aug, 11th Sep, 16th Oct, 13th Nov, 11th Dec
Currently I am using standard calendar for this but wants to change it to extended calendar to avoid manual inserts for every year.
#Manvi
not very confident of the exact condition and this would be a partial answer.
as for now i can think of
WEEK#03|WEEK#07|WEEK#11|WEEK#15|WEEK#20|WEEK#24|WEEK#28|WEEK#33|WEEK#37|WEEK#42|WEEK#46|WEEK#50
This would give you all the 3rd week of the the months and then hereon need to exclude the rest of the days.
You can refer this link for condition keywords.
Also, you can use below to include multiple keywords for desired output.
OR condition as "|"
NOT as "NOT"
Hope this helps. Good luck.
Will update incase i do find the solution.
Edits:
The first working day would definitely be a Monday and the previous day has to be 2nd Sunday.
Consider a calender as below
extended_calendar: Cal_name
description: 1st day of the 3rd week
workday: mo,tu,we,th,fr
non_workday:
holiday:
holcal:
cyccal:
adjust: +1
condition: sun#2
Sun#2 would consider the 2nd sunday of all months and the next day would mark the start of the 3rd week.
To consider the next day of the 2nd sunday adjust: +1 defined.
If you are looking for the 2nd day of the 3rd week. Defined adjust to +2.

Implentation of a date in SQL Server

Disclaimer: I am just looking for a logic not code
John discovered a strange island called Rasa. The years and weeks on the island are weird. Digging deeper into the island's calendar, he found out that it is similar to rest-of-the-world's (ROW) calendar but the island calendar's Year starts on 1st week of February's calendar. John is asking you to help him solve the problem of converting ROW's calendar into Island's calendar. Here is the question.
You are given a date (today's date). You have to determine the Island week's number. The catch here is that the Island year starts from 1st week of February and every Island's week starts from Sunday and ends on a Saturday. Write a SQL statement in SQL Server to achieve this. Use SQL Server functions and devise a logic.
Input parameter: Any date.
Output parameter: Week No in Rasa Calendar.
Here is an example:
Date: 5th May 2015 --
Week No in ROW Calendar:19
Week No in Rasa's Calendar:14
Date: Jan 1 2017:
Week No in ROW Calendar:1
Week No in Rasa's Calendar:49
My question: can this be achieved in SQL Server?
My homework: I tried a couple of ways to solve the problem.
Approach #1:
Step 1: Calculate the total no of days between today and Feb 1.
Step 2: Divide it by 7 and add 1 to the result.
Later found out that this approach will not work if Feb 1 is on any day other than Sunday.
Eg: 1st Feb is on Wednesday. 5th Feb will be on Monday
So, 1st Feb is on Rasa's week 1, and 5th Feb is on Rasa's week no 2. According to my approach 1st and 5th feb are on week 1 which is incorrect.
Approach #2:
I thought removing 5 weeks of Jan from ROW's calendar should work
select
case
when f.RasaWeek = -4 then 48
when f.RasaWeek = -3 then 49
when f.RasaWeek = -2 then 50
when f.RasaWeek = -1 then 51
when f.RasaWeek = 0 then 52
else
f.RasaWeek
end as Rasa_week,
f.year, f.month, f.date
from
(select
datepart(wk, date) - 5 as RasaWeek, *
from
<datetable>
where
Year(date) in (2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018)) as f
Info: I tested this on a <datetable> but this code will break if there is a 53rd week. Notice that I was not able to take care of the 53rd week.
Any inputs to solve this problem are welcome.
With dates, it's almost always easier to make a calendar table and store the data you care about rather than trying to do anything beyond basic date arithmetic. Use SQL's strengths: storing and retrieving data.
In this case, what you care about are all of the first Sundays in February. If you store these dates in a table, the solution is:
RETURN
SELECT TOP 1
DATEDIFF(day,[date],#input_date) / 7
FROM IslandCalendarStartDates
WHERE [date] <= #input
ORDER BY [date] DESC
This way you don't need to worry about leap years or 53-weeks, or any of the edge cases. Just count the days from the most recent first Sunday in February and divide by 7. If you need to change the solution to accommodate a different start date, you only change the data, not the code.

SSRS BIDS 2008 Parameter Date Range

I have produced a report where the user will need to view financial years data.
So for example April 2010 - March 2011 will have one years data however if the user selects this as in my image, data for January, February, March in 2010 will be brought as well as January, Febrary and March 2011, when I dont want the Jan,Feb,Mar for 2010 as the financial year begins in April.
I therfore need to be able select a data range using parameters to stop bringing data through that I didnt ask for.
Can anyone advise me how to do this?
You can build a month-year key to use instead of your ad-hoc year and month parameters. You can then display it for example as YYYY/MM - so that you can select 2010/04 through 2011/03.
Another option would be to have from month (with year) to month (with year).
Yet another option would be to have a year, month, and number-of-months, selecting 2010, 04, then 12 for number-of-months.
Your two parameters aren't aware of eachother in the way that you want it to be.

Resources