Date Expression in SSRS
I have a query in MS SQL database which i want to create a report with that but the report should use a date chosen by the user. Now my problem is when the user chooses today's date, I want the query to select yesterday date and match it with date from the
query and display the result.
I want these date form like, if user chooses today, I need
Yesterday date,
two days ago date,
one month ago date,
two months ago date,
one year ago date, and
two years ago date
all from the single selection of today's date
you can do it via SSRS expression or using t-sql
in t-sql you can do it like this
DECLARE @dt datetime
SET @dt = GETDATE() -- your passed date
SELECT DATEADD(dd,DATEDIFF(dd,0,GETDATE()),-1) AS YesterdayDate,
DATEADD(dd,DATEDIFF(dd,0,GETDATE()),-2) AS TwoDayAgoDate,
DATEADD(mm,DATEDIFF(mm,0,GETDATE())-1,DAY(GETDATE())-1) AS OneMonthAgoDate,
DATEADD(mm,DATEDIFF(mm,0,GETDATE())-2,DAY(GETDATE())-1) AS TwoMonthAgoDate,
DATEADD(mm,DATEDIFF(mm,0,GETDATE())-12,DAY(GETDATE())-1) AS OneYrAgoDate,
DATEADD(mm,DATEDIFF(mm,0,GETDATE())-24,DAY(GETDATE())-1) AS TwoYrAgoDate
In SSRS you can use expression like below
Yesterdays date
=DateSerial(Year(Parameters!DateParam.Value),Month(Parameters!DateParam.Value),Day(Parameters!DateParam.Value)-1)
two days ago
=DateSerial(Year(Parameters!DateParam.Value),Month(Parameters!DateParam.Value),Day(Parameters!DateParam.Value)-2)
One month ago
=DateSerial(Year(Parameters!DateParam.Value),Month(Parameters!DateParam.Value)-1,Day(Parameters!DateParam.Value))
two month ago
=DateSerial(Year(Parameters!DateParam.Value),Month(Parameters!DateParam.Value)-2,Day(Parameters!DateParam.Value))
one year ago
=DateSerial(Year(Parameters!DateParam.Value)-1,Month(Parameters!DateParam.Value),Day(Parameters!DateParam.Value))
two year ago
=DateSerial(Year(Parameters!DateParam.Value)-2,Month(Parameters!DateParam.Value),Day(Parameters!DateParam.Value))
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
Similar Messages
-
Convert String to Date and Format the Date Expression in SSRS
Hi,
I have a parameter used to select a month and year string that looks like: jun-2013
I can convert it to a date, but what I want to do is, when a user selects a particular month-year (let's say "jun-2013")
I populate one text box with the date the user selected , and (the challenge Im having is) I want to populate a text box next to the first text box with the month-year 2 months ahead. So if the user selects
jun-2013 textbox A will show jun-2013
and textbox B will show aug-2013..
I have tried:
=Format(Format(CDate(Parameters!month.Value ),
"MM-YYYY" )+ 2 ) -- But this gives an error
This returns the month in number format like "8" for august...
=Format(Format(CDate(Parameters!month.Value ),
"MM" )+ 2 )
What is the proper syntax to give me the result in this format = "aug-2013" ???
Thanks in advance.
MC
M CollierYou can convert a string that represents a date to a date object using the util.scand JavaScript method, and then format a date object to a string representation using the util.printd method. For more information, see:
http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1254.html
http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1251.html
In your case, the code would be something like:
var sDate = "2013-01-10";
// Convert string to date
var oDate = util.scand("yyyy-mm-dd", sDate);
// Convert date to new string
var sDate2 = util.printd("mm/dd/yyyy", oDate);
// Set a field value
getField("date2").value = sDate2;
The exact code you'd use depends on where you place the script and where you're getting the original date string, but this should get you started. -
Using an expression in SSRS to display rolling 12 month and year to date volumes
I need some help in writing an expression in SSRS. I have a table that contains date columns and rows that contain different types of data groups. (e.g. total number of items received during the month, total dollars for the month, etc.) I want to add two
new columns to the end of the report that will display a rolling twelve month total for each of the different rows of data. Plus a column that would show year to date totals for the same rows.
I was thinking I could accomplish this by adding expressions for each row in the new 'rolling twelve month' and 'YTD' columns in my report however, I'm not sure how to structure the expressions to achieve this.
Here is an example of how my report currently looks. (I added a pipe delimeter in case the formatting changes once this is submitted.)
Jan-2014 | Feb-2014 | Mar-2014 | Apr-2014 | Rolling 12 mth | YTD
Items received 100 | 35 | 45 | 12 | 192 | 192
Dollars $50.00 | $25.00 | $120.00 | $15.00 | $210.00 | $210.00
Any guidance you can provide would be appreciated.
Thank youThis example shows how to get what you need. It'll take modifying your query to add two cased columns onto the end.
DECLARE @forumTable TABLE (periodYear INT, periodMonth INT, periodMonthName VARCHAR(12), periodDollars MONEY, periodItems INT)
DECLARE @i INT = 0
SET NOCOUNT ON
WHILE @i < 24
BEGIN
INSERT INTO @forumTable (periodYear, periodMonth, periodMonthName, periodDollars, periodItems)
VALUES (YEAR(DATEADD(MONTH,-@i,GETDATE())), Month(DATEADD(MONTH,-@i,GETDATE())), DATENAME(MONTH,DATEADD(MONTH,-@i,GETDATE())), 1000-@i, 100-@i)
SET @i = @i+1
END
SET NOCOUNT OFF
SELECT *,
CASE WHEN CONVERT(VARCHAR,periodYear) + '-' + CONVERT(VARCHAR,periodMonth) + '-01' > DATEADD(MONTH,-12,GETDATE()) THEN periodItems ELSE 0 END AS ytdItems,
CASE WHEN CONVERT(VARCHAR,periodYear) + '-' + CONVERT(VARCHAR,periodMonth) + '-01' > DATEADD(MONTH,-12,GETDATE()) THEN periodDollars ELSE 0 END AS ytdDollars
FROM @forumTable -
How to give specific default date with expression in SSRS
Hi,
I have to pass some specific kind of dates in "Default Values" section of parameter.
1st is whenever SSRS report run for any year in default date I want to pass value 1/1/(Current Year), for this I tried many way like , = "1/1/" + DatePart("Y",Now()) also = "1/1/" + Year(Now()) but it
is giving me error. When I tried both part individually "1/1/" and DatePart("Y",Now()) , it is working but when I join them with + sign it is giving me error that "input string is not in correct format"
2nd I want to set up like when package run in month of April, it takes default date as "(Previous Month, which is May)/1/(current Year)" so if I am running report on 4/5/2013 then it in default date it should take 3/1/2013.
Please help me with the expression. Thanks in advance.
VickyHi Visakh,
Thanks again.
I have one more question, I also have start date and end date. In start date I can put your expression as you gave me as below,
=DateAdd(DateInterval.Month,DateDiff(DateInterval.Month,CDate("01/01/1900"),Now())-1,CDate("01/01/1900"))
But can you please help me with End date expression?
In End date I want to put previous month's last date. For example, if active batch is running package on
12/16/2013 then for End Date parameter it should value "11/30/2013"
For 1/16/2014 then for End Date parameter it should value "12/31/2013"
For 3/16/2013 then for End Date parameter it should value "2/28/2013"
Thanks for your help in advance.
Vicky -
How to use string as an expression in SSRS reports
Hello all,
I have created a SSRS report in which I have used a tablix and a single dataset (ds_test)
Now the dataset use t-sql and is calling a table in which has data as shown below:
What I am trying to do is to use this as an expression inside the cell of the tablix. But when I run the report It give me:
But It should show the result as "True", I know it is taking this as a string but is there any way so that we can use this as an expression in the report
NOTE: We cannot use this directly in report , because this is generated dynamically and should always present in DB tables only
Thanks in advance
Pankaj Kumar Yadav-So your table has a varchar column with 'iif(1=1,True,False)' in one of the records ?
yes
Pankaj Kumar Yadav-
You wont be able to pass a value from db like this and use this as an expression inside SSRS.
If you're using SQL 2012 you can exec this expression using dynamic sql and then show return value as is in a SSRS report.
SSRS is a presentation tool with limited scripts and it cant do any query processing against database. that part have to be implemented using t-sql query on backend (dataset)
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Hi All;
I am using below formula for date order in SSRS
=Format( Fields!scheduledstartValue.Value,
"MM yyyy")
Date comes in teh order as below
for teh year 2014 order is right but 2015 should be at the last
Any much appreciated
Thanks
Pradnya07Thats because Format causes values to return as string type
Use sort expression as
=Fields!scheduledstartValue.Value
And use the format expression only for the display
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Hi...
I am stuck with expression in SSRS. am writing this in expession :
=IIF(Parameters!Month.Value = "1", MonthName(Parameters!Month.Value + 11),
MonthName(Parameters!Month.Value)
when i run this expression and value = 1 (mean true) then it run properly and show result "December"
but when value <> 1 (mean false) then it retruns error message "Error"
further if i write like this :
=IIF(Parameters!Month.Value = "1", MonthName(Parameters!Month.Value + 11),
MonthName(Parameters!Month.Value - 1)
both true and false return "Error"
what am doing wrong
Please help... Urgent
thanksSo you show year in a different parameter? Assuming you've parameter named Year then it would be this
=Parameters!Year.Value + (((Parameters!Month.Value-1)+11) / 12 )
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Hello,
We have requirement to use the REST web service as the Data source of SSRS. Tried with XML as Data Source, but unfortunately I could not succeed because the query expects SOAPAction which is not available in REST Service.
Do we have any option to use REST Service, if so please provide some basic example, so that I can try out some options.
If not, do we have any alternate solutions to handle these situations?
Thanks!
VinayHi Vinay.
After looking on it for some time, I am afraid currently there is no document to talk on how to use the REST web service as a data source.
You can use the link
http://technet.microsoft.com/en-US/library/aa964129(v=SQL.90).aspx for a renference.
From a support perspective currently this is really beyond what we can do here in the forums. If you cannot determine your answer here or on your own, consider opening a
support case with us. Visit this link to see the various support options that are available to better meet your needs: http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone
Thanks, -
Outlook/Exchange data source in SSRS
Hi,
Is it possible to connect to Outlook or Exchange via SSRS as a data source? Is it possible to create a data source in SSRS from an inbox?
Thanks!
-OptionHi,
I don't think there is a way, out of the box to connect to Exchange Server from Reporting Services.
For a complete list of data sources supported by SSRS(pasted below), see Data
Sources Supported by Reporting Services (SSRS)
Microsoft SQL Server
Microsoft SQL Server Analysis Services for MDX, DMX, Microsoft PowerPivot, and tabular models
Microsoft Azure SQL Database
SQL Server Parallel Data Warehouse
Oracle
SAP NetWeaver BI
Hyperion Essbase
Microsoft SharePoint List
Teradata
OLE DB
ODBC
XML
Faisal Muhammed My Blog -
Date Expression showing Error in SSRS
Hi,
I have value for Month field as 0. I have used MonthName function in the report. So im getting error as #Error
Expression:
MONTHNAME(Fields!Month.Value)& " "& Fields!Day.Value &" "& Fields!Year.Value
Please help me to resolve the issue.
Thanks in Advance..
Regards,
LuckyAbdulHi,
I want to show if the monthValue = 0 then it should show as N/A or any other. If the monthvalue is 1 to 12 then i need to show as monthname of the monthvalue.
Expression:
MONTHNAME(Fields!Month.Value)& " "& Fields!Day.Value &" "& Fields!Year.Value
Example:
if my monthvalue is 0 then
output should be
N/A
if my monthvalue is 1 then
output should be
January 21 2014
Please help me to resolve the issue.
Thanks in Advance..
Regards,
LuckyAbdul -
Can I add a datetime filter to an expression in SSRS
I am using SSRS to create a tablix that displays weekly, monthly and yearly values. My query contains data for the entire year. I would like to avoid creating 3 Datasets and then displaying three tables together (which I have already tried and did not like
because occasionally the current week or month does not have the same number of rows in the Tablix. )
I am trying to create an expression that shows the Sum of the values
Sum(Fields!Sale.Value)
when the sales are equal to the current week, month or year
DATEPART(wk, sale_date) IN (DATEPART(wk, @week)
DATEPART(month, sale_date) IN (DATEPART(month, @week)
DATEPART (year, sale_date) IN (DATEPART(year, @week)
Any ideas?Hi PrandyJosselyn,
Per my understanding that you have an date field in table(Sale_date) and you want need to calculate the week sales, month sales, year sales based on this date, you need to filter the data of the yearly, monthly, weekly to display in the report based on the
filter, right?
I have testedon my local environment and you can modify the query in the main dataset as below to get add the week number, month number, year number if they didn't exists in the db, create three cacading parameter to display the values of "Year Number","Month
Number","Week Number".
Details steps below for your reference:
1.Modify the query in the main dataset as below to add the filter of the three parameters:
SELECT Sale, Sale_Date, DATEPART(wk, Sale_Date) AS weeknum,DATEPART(month, Sale_Date) as monnum,DATEPART (year, Sale_Date) as yearnum
FROM tablename
where DATEPART(year, Sale_Date) =(@YearNum) and DATEPART(month, Sale_Date) =(@MonNum) and DATEPART(wk, Sale_Date) =(@WeekNum)
2.Create and new DateSet2 and create Parameter1(YearNum) which get the values from this dataset and use this expression:
SELECT DATEPART(year, Sale_Date) AS YearNum
FROM TableName
3.Create and new DateSet2and create the Parameter2(MonthNum) get the values from this dataset and use this expression:
SELECT Distinct DATEPART(month, Sale_Date) AS MonthNum
FROM TableName
where (DATEPART(year, Sale_Date) = @YearNum)
4.Create and new DateSet3 and create the Parameter3(WeekNum) get the values from this dataset and use this expression:
SELECT Distinct DATEPART(wk, Sale_Date) AS WeekNum
FROM TableName
where (DATEPART(year, Sale_Date) = @YearNum) and (DATEPART(month, Sale_Date) = @MonthNum)
5.Design the report to add group for the year and month:
If you still have problem, please provide the sample data of the table in DB and the snapshot of the report structure you have designed.
Any problem, please feel free to ask.
Regards
Vicky Liu
Vicky Liu
TechNet Community Support -
How to show data output in SSRS
Below is my simply query. I need to use Matrix SSRS format. I will put "Region" in "row" column, Header will use "Customer_Requested_Date" field, and will use "Amount" in the data session.
The data output in the "Header" field will show January.....until December (current month is December). In the Amount field under "December" (current month), I need to compute the formula like "Customer_Request_Month"
< = Current Month". (I do not have the field name called Current Month, need to get a Date/Time function to display Current Month).
How I can come up the data output under December Header field to show the current Amount in that section?
November, 2014
December,2014
Region
Amount
CRD Month < = Current Month
Select
Customer_Request _Date,
Customer_request_Month,
Transaction_Type,
Region,
Amount
From Table
Thanks,
Josephine
Josey TangHi Josey,
According to your descritption, you want to show the current month in your tablix. Right?
In Reporting Services, we can use the Now() and datepart() function to get the current month. Please use the expression below:
=Datepart("m",Now())
In this scenario, since you want to show the amount of current month within the column group, you need to create another dataset which always show the data of current month. Then you can use lookup() function to get the amount value from the current dataset
based on the Region. Please follow the steps below:
Create a same dataset(DataSet2) using your query. Add a filter on this dataset. Make Fields!Customer_request_Month.Value
=
Datepart("m",Now())
Then add a column inside of column group, using the expression below:
=lookup(Fields!Region.Value,Fields!Region.Value,Fields!Amount.Value,"DataSet2")
The design and result look like below:
Reference:
Expression Examples (Report Builder and SSRS)
Lookup Function (Report Builder and SSRS)
If you have any question, please feel free to ask.
Best Regards,
Simon Hou -
Overlapping data when more data column chart SSRS
Hi guys,
In my ssrs report the column chart display is not good when more number of datas are viewed.How to overcum this issue
I searched more on this issue no good solution found.
I attached screenshot for this report,
any suggestions pls
Thanks,
R.BHi R.B,
I can reproduce the issue in my local environment. If there are more column data with adjacent values in the chart, the label will be overlapped due to the insufficient space. In this scenario, there are several properties you can use to try to get the labels
to fit better. Click the data point to open the Properties Windows, then go to the SmartLabels node.
Expand the "NoMoveDirections" node. This will give us a lot of directions that we can use to restrict the directions that the labels can move in. We can try to change directions to see if it helps.
Try to enlarge the chart size and use the method below to adjust the column size, it will free up more space to contain the label.
http://www.bidn.com/blogs/ChrisAlbrektson/bidn-blog/1832/ssrs-adjust-bar-chart-width
If we want to remove the black arrow, we can refer to the following thread:
http://social.technet.microsoft.com/Forums/en-US/e3019086-4f72-4898-ba86-2e7c97c8fae4/ssrs-series-lable-overlaping-issue?forum=sqlreportingservices
Alternatively, we can use Tooltip property to instead of actually displaying. Type the same expression with Value field in the Tooltip property.
Hope this helps.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Default Date Parameters for SSRS Subscription
I have a SSRS 2008 R2 report running on a Sharepoint 2010 site.
It has two date parameters (Beginning and Ending Date).
The defaults of these dates are calculated correctly when running interactively.
For example:
=DateAdd("d",-28, Today)
=DateAdd("d",-1, Today)
However, when you create a subscription the defaults are based on when the report is submitted and not when the report is executed.
Is there anyway to set a subscription to pull the default parameters every time when executed.
Thanks in advance.Hi miguelh,
Based on my research, if we specified the report parameters with “Use Report Default Value” is checked in the subscription, we could get the report from this subscription with the default value. The default values are based on the expression when the subscription
is executed, rather than the time when we create the subscription. If today is 7/21/2014, the Beginning Date is 6/23/2014, Ending Date is 7/20/2014.
So, please double check you have typed the expressions as the default values in the two date parameters and we have select the “Use Report Default Value” as the parameter values when creating the subscription .
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Static Data Formatting in SSRS VS2010
Hello - I hope you guys are having a wonderful day so far!!
I am using a SQL Server 2012 with VS 2010. In my SSRS report, I have a SP based data set. On top of what the report pulls based on user entered parameters, I want 6 rows of additional static data to be included in the report. So, at the bottom of the report
I created 6 static fields and manually entered all the hard coded values. Please mind that these static values repeat every month. So far works great. My challenge is to format the amount field. Although, I was able to change the text box properties and formatted
the values as 'Currency' but it does not come across currency when a report is rendered. In addition to that I have a ID field which increments by number based on # of rows. Last 6 rows of static data do not have IDs in front of them. Similarly, the user entered
parameters 'Start Date' and 'End Date' are also not populated for those static rows. So, how is it possible to assign IDs, user entered parameter values and values formatting in the static rows? I am wondering if any solutions applying expressions are available
or even possible? Gurus, please suggest. Thank you again!
SJ
Sanjeev JhaHi SQLTurtleReally,
According to your description, you want to sum the values in the appended static row and the total value of detail rows. Also you have a column to show the row numbers and include those static rows. Right?
In Reporting Services, when we use build-in Aggregation function, it only works within a scope, this scope can be Group, data region or DataSet. In this scenario, even the static rows are in the tablix, it has nothing to do with the detail rows, they are
not in a same scope. So the RowNumber() and Sum() function can never include the values in those static rows. For your requirement, the most effective workaround is add these hard code values into database as records so that they will be in same DataSet with
the detail rows.
Reference:
Aggregate Functions Reference (Report Builder and SSRS)
If you have any question, please feel free to ask.
Best Regards,
Simon Hou
Maybe you are looking for
-
Number of records displayed in the lookup field on webconsole dont change
Hi All, Issue here is- When I select a report or process form to select a value for anything and click on the magnifying glass (lookup field) in web console, should get all the resources in the page that pops up. For now it only displays 10 records p
-
Issues after copying a query from one IP to another
Hi Friends, I have a query which was built on a infoset, i have built a multi provider with aditional objects apart from what i have in the infoset, i.e. this Multi provider has all the objects which are used in the query. I have copied the query fro
-
Hi, we are using F110 for making vendor payments, with EDI payment method. we came accross a situation where, after completing APP, it is possible to update manual checks in FCH5 for the same payment document that is already paid via EDI. can u pls s
-
Hide top axis in cross tab report
Hi How to hide top axis in webi report xir4. Only objects names on top axis to be hide. I see only option for data fold and unfold Please suggest. Thanks.
-
I Can't open archives in photoshop
My photoshop cs3 can't open archives...I try everything but not work, I press archive/open and crash the program the only way to close is ctrl/alt/sup.