I'm working in SSRS and I'm trying to create dynamic month and year header columns to look like this:
Oct 2015 | Nov 2015 | Dec 2015 | Jan 2016 | Feb 2016
The code I've tried is this:
=MONTHNAME(Today), TRUE) & " " & YEAR(Now)
This gives the desired result, and I know if I do +1, it'll go to the next month or year, but what happens when it turns January? How can I make sure next year's months have 2016?Is this possible? Not sure if I'm making sense on this, but I can clarify if needed.
Basically, I have 12 columns that have the months in them, and the column names will slowly move to the left. How can I make sure the year corresponds with the correct month when the year changes?
Never mind I found my answer. Here's my solution if anyone else needs it. What I had to do was another if statement when the month's value was greater than 12, add 1 to the year value. If it's not, it will default to the current year.
=MONTHNAME(IIF(MONTH(Today)+4>12,MONTH(Today)+4-12,MONTH(Today)+4), TRUE) & " " &
IIF(MONTH(Today)+4>12,YEAR(NOW)+1,YEAR(NOW))
Thanks for the tips guys!
Glad you were able to figure out a way.
There's more than one way to skin a tauntaun:
=MONTHNAME(DATEADD("M", 4, Today()), TRUE) & " " &
YEAR(DATEADD("M", 4, Today()))
Related
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")
I have a problem with times conversion.
In my database, I have 2018-08-20 08:30:11.000 PM and I can't change this format.
When I use =Fields!DateTime.Value, I display the date like this (it's only example).
But I want to display it in this way (date is ok) 2018-08-20 20:30:11.
I thought about searching this value and when it will be PM then add 12 to hour but it doesnt work... I have no more ideas...
=Format(Fields!DateTime.Value,"MM/dd/yyyy") & Environment.NewLine & iif (Fields!DateTimeValue="PM"), Format(Fields!DtTmStart.Value="HH+12:mm:ss")
Could somebody help me? Please!
The following expression should give you what you need...
=Format(Fields!DateTime.Value,"yyyy/MM/dd HH:mm:ss")
Note the upper case HH, this gives 24 hour format (hh = 12 hour format)
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.
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. :-)
I'm trying to have 3 combo boxes for users to enter dates. The Month and Year combo boxes are very easy but I'm having trouble with the day combo box. I want this to be an intelligent box in that it will only display days based on the month, ie. 28 when month is set to February and 31 if on January.
I'm just wondering if there is an easy way I should look at to accomplish this, I tried some VBA that was unsuccessful.
What I have done is that I essentially used addItem for all days 1-28 and then had IF checks to see if i needed 29, 30 or 31 days. Errors occurred when I would go from a month with 31 days to 30 and then to 29/28 because it would attempt to remove 31 from the list but it wouldn't exist since when switching to the 30 day month got ride of 31. Unless there's a way to bypass this I need a pointer to the right direction.
You can say something like:
Me.cboDay.RowSource = "SELECT Number " _
& "FROM MyNumbersTable " _
& "WHERE Number < = " & Day(DateSerial(Me.cboYear,Me.cboMonth+1,0))
Where MyNumersTable is a table of integers
Note that
Day(DateSerial(2012,2+1,0)) = 29