Reporting Services Sorting by Date issue with TFS Report - datetime

Long time reader etc,
I've a TFS report that I want to alter the sorting on by date. The problem is the sort only seems to consider the day element and the rest isn't considered. For example, the following is happening:
1/7/2011
1/7/2011
1/7/2011
2/12/2010
3/03/2011
3/03/2011
I've looked for a way to specify the datatype on the box in the table but to no avail. Any suggestions?

I've realised the field was being treated as text as the date in question isn't guaranteed to be there and replaced with an empty string if it wasn't.
Two steps have fixed the problem:
Added calculated field to dataset and wrapped an iif around to deal with missing dates as being way off in the future.
=CDate(IIf(IsDate(Fields!My_Date.Value), Fields!My_Date.Value, DateAdd(DateInterval.Year, 10,Now)))
This then forces the field to be treated as a date. I then added a sort on the group on this calculated field which isn't shown in the report and gives the impression that those items with a date get ordered and the rest are left to the other layers of sorting which is correct.
Is there a better way of doing this?

I find it a very efficient way!
I did it myself more complex
Group properties of the field you want to sort on
Sorting
expression:
=Datepart("yyyy",Fields!Datum.Value) & Datepart("m",Fields!Datum.Value) & Datepart("d",Fields!Datum.Value)
It will sort first on year, then on month, then on day

Related

"Calculated columns cannot contain volatile functions like Today and Me" error message on Sharepoint

I try to add a new calculated column to sharepoint list that will show elapsed day. I enter name and write a formula like;
=ABS(ROUND(Today-Created;0))
The data type returned from this formula is: Single line of text
When I want to save I get an error like
Calculated columns cannot contain volatile functions like Today and
Me.
Calculated Column Values Only Recalculate As Needed
The values in SharePoint columns--even in calculated columns--are stored in SharePoint's underlying SQL Server database.
The calculations in calculated columns are not performed upon page load; rather, they are recalculated only whenever an item is changed (in which case the formula is recalculated just for that specific item), or whenever the column formula is changed (in which case the formula is recalculated for all items).
(As a side note, this is the reason why in SharePoint 2010 you cannot create or change a calculated column on a list that has more than the list view threshold of 5000 items; it would require a mass update of values in all those items, which could impact database performance.)
Thus, in order for calculated columns to accurately store "volatile" values like "Me" and "Today", SharePoint would need to somehow constantly recalculate those column values and continuously update the column values in the database. This simply isn't possible.
Alternatives to Calculated Columns
I suggest taking a different approach entirely instead of using a calculated column for this purpose.
Conditional Formatting: You can apply conditional formatting to highlight records that meet certain criteria. This can be done using SharePoint Designer or HTML/JavaScript.
Filtered List views: Since views of lists are queried and generated in real time, you can use volatile values in list view filters. You can set up a list view web part that only shows items where Created is equal to [Today]. Since you can place multiple list view web parts on one page, you could have one section for today's items, and another web part for all the other items, giving you a visual separation.
A workflow, timer job, or scheduled task: You can use a repeating process to set the value of a normal (non-calculated) column on a daily basis. You need to be careful with this approach to ensure good performance; you wouldn't want it to query for and update every item in the list if the list has surpassed the list view threshold, for example.
I found some conversations about this issue. Many people suggest to creating a new Date Time column, visible is false, default value is Today's Date and it will be named as Today. Then we can use this column in our formulas.
I tried this suggestion and yes error is gone and formula is accepted but calculated columns' values are wrong. I setted column Today is visible and checked, it was empty. Default value Today's Date was not working. When I looking for a solution for this issue I deleted column Today carelessly. Then I realized calculated columns' values are right.
Finally; I don't know what is trick but before using Today keyword in your formulas if you create a column named as Today and after your formula saving if you delete Today column, it is working.
UPDATE
After #Thriggle's answer I realized this approach doesn't work like a charm. Yes, formula doesn't cause an error when calculated column saving but it works correctly only first time, in the next day the calculated column shows old values, because its values are static as Thriggle explained.

Access 2010 Query with Parameter and Sort

I have a problem that I've been going round and round with in Access 2010. Imagine a table with these columns:
Name Date Time
Now, I have a query that asks the user to input a begin date and an end date and returns all records that are between those two dates. This works fine. However, as soon as I add a sort to the Date column things go awry. Once you put a sort on a column with a parameter the user gets asked to enter the parameter twice. From what I've been able to find out this is normal (although annoying) behavior in Access.
If I add the Date column in a second time and show the column with the sort and don't show the column with the parameter it works fine. The query would look something like:
Name Date (shown & sorted) Date (not shown & parameters) Time
Now when I run the query it all works well and comes out the way I want it to. This would obviously be a great solution then. However, there's another problem. When I save the query, leave, and reopen the query the two columns are merged back into each other. Thus, the change is lost and the user again sees two inputs.
My question is this: what can I do differently to achieve the desired results?
Some possible things I've thought about but don't know the answer to are:
Is there a way to make it so the columns don't merge? Do I have to use a form with the input boxes and take the data from that (I'd prefer not to do that as it will require a lot of additional work to handle the various things I am doing in the database). Is there some obvious thing I'm missing?
Thanks for any suggestions.
FYI: Here is the SQL from the query
SELECT Intentions.Intention, Intentions.MassDate, Intentions.[Time Requested], Intentions.[Place Requested], Intentions.[Offered By], Intentions.Completed
FROM Intentions
WHERE (((Intentions.MassDate) Between [Enter start date] And [Enter end date]))
ORDER BY Intentions.MassDate, Intentions.[Time Requested];
It is true that sometimes the Query Designer in Access will "reorganize" a query when you save it. However, I don't recall an instance where such a reorganization actually broke anything.
For what it's worth, the following query seems to do what you desire. After saving and re-opening it looks and behaves just the same:
For reference, the SQL behind it is
PARAMETERS startDate DateTime, endDate DateTime;
SELECT NameDateTime.Name, NameDateTime.Date, NameDateTime.Time
FROM NameDateTime
WHERE (((NameDateTime.Date) Between [startDate] And [endDate]))
ORDER BY NameDateTime.Date DESC , NameDateTime.Time DESC;
I have had the same problem and I have discovered the reason:
If, after you have run your query, sort a collumn in the result grid and the say yes to save changes to the query the sort action will be stored with the query. This will actually cause the query to run twice. First to create the result and then one more time to sort. You'll therefore be asked twice for the parameters.
SOLUTION: Run the query (entering your parameters twice ;-) ). Then remove the Sorting by clicking on the AZ-eraser symbol in the task bar above (in the sorting compartment).
Then open your query in design-mode and add the sorting order to the appropriate collumn.
Your are then good to go.
Regards
Jan

SSRS Chart Blank with DateTimes

I am working with SSRS and having trouble creating a graphical chart to display data. My dataset is very simple, as it only has one column which is a datetime field (known as CreatedOn).
My SQL query is:
SELECT [CreatedOn]
FROM [Incident]
WHERE CreatedOn > DATEADD(m,-11, DATEADD(
month, DATEDIFF(month, 0,CURRENT_TIMESTAMP), 0))
My goal is to have the query results show up in a chart and have them grouped by year and by month, as well as sorted. For example, I should be able to see that 40 incidents were created in February 2005. Those 40 incidents would be represented graphically as a single bar (it is a bar graph) with the number 40 on top (or somewhere).
My issue is that either my chart shows up completely blank, or the report fails to run. When it fails to run, the error I receive is:
the value expression for field 'CreatedOn' contains an error: conversion from string 'CreatedOn' to type 'Date' is not valid.
I have tried using SSRS expressions on the CreatedOn field, such as CDate() and FormateDateTime(). That does get the report to run, but the chart shows up blank. I would not think that the field should have to be formatted or converted in SSRS since it is already a datetime field at the database level. I have tried about 10 different combinations of groupings and sorts, but my chart always shows up blank. I have even used CDate() and so forth in the grouping and sort expressions which are a part of the chart.
How can I get my bar chart to work (a.k.a. show datetimes, grouped and sorted)?
I am going to go off the assumption:
You have more data being pulled than just the ‘CreatedOn’ field.
a. Because if you don't it will be difficult to create a chart as you have nothing else to compare it too.
If this is an accurate assumption here is an example of how to create a chart and have the data formatted by dates.
When designing a chart you need to take a lot into consideration. First I like to ensure that I have as little null data as possible. This causes charts to act wonky (at least from my experience).
Second is how the data will be represented.
We have several things to consider when we think about charts and groups.
There are Category groups, Series groups, and then the Values.
According to Microsoft: charts have a direct similarity to Matrix’s. They act the same way:
The Column groups of a Matrix are similar to that of the Category Groups in a chart.
The Row groups of a Matrix are similar to that of the Series Groups in a chart.
The Data area of a Matrix is similar to that of the Values Groups in a chart.
Setting Up the chart:
If we want the number of Incidents sorted by Year and then Month it might look something like this:
Year by Category (You can use your group by Expression here) =Year(Fields!CreatedOn.Value)
Incidents will be in the Values section =Count(Fields!Incidents.Value)
Once you have that working and showing data I would then start adding in the data for the month. Again thinking about how you want to have the data displayed. You could then add a second Grouping on the category under the other one with your month function.
Another Useful link on charts (I know this is a little older but it’s details are still relevant)
*Side Note: When dealing with dates it can be a little tricky especially if SSRS is not recognizing something as a date. Here is a useful link that I have used when dealing with dates.
Dates
I hope this helped!
The issue was that the CreatedOn date field was not being defined correctly.
My data source was defined using an expression which depended upon parameters, using the expression: ="Data Source=sql01;" & "Initial Catalog=" & Parameters!ParentID.Value. Because the dataset must be defined at the runtime of the report, I was not able to refresh fields in the dataset using the "Refresh Fields" button.
I thought that I could work around this by defining the CreatedOn field manually. On the first attempt, SSRS threw an error at runtime claiming that I was trying to convert a string to a date, which basically meant that it perceived the CreatedOn field as defined within the dataset as a string. So I then tried to use the CDate() expression in the definition of the field, but that left me with a completely blank graph.
The solution was to:
Delete all of the fields I already had defined within the dataset
Temporarily hard-code my data source to use a database (Data Source=sql01;Initial Catalog=MyDatabaseName)
Click the "Refresh Fields" button within the dataset
Go back at set the data source to the original data source I wanted which depended upon parameters.

Convert multiple gridview date fields into one format

I'm spinning my wheels right now and what I'm pretty sure is an easy answer, I just can't see at the moment. What I'm attempting to do take two sets of converted dates in a database and I want to present them in a grid view as one single date format.
Right now the two date formats are as follows:
YYYYMMDD
mon dd yyyy hh:miAM/PM
I want to convert them all into one format. For giggles, lets just convert them all to 112 (YYYYMMDD).
Now I want to present this all in the same SELECT statement that populates my gridview with other columns of data of various forms lots of text, data entry, long characters, etc.
The thing I haven't been able to wrap my head around is how to put this into a SELECT statement that includes all the rest of the information that populates the gridview.
So a normal SELECT statement (into all nvarchar(max) fields...the table is formed this way because we deal with lots of non standard data importing like Unix) would look like this (this is just a sample database):
SELECT [record_number], [price], [product], [description], [date_of_order], [customer_id] [comments]from sample_database
When presenting the 'date_of_order' field, I figured I need to use a CAST or CONVERT with the proper conversion numbers. However, after looking online I'm scratching my head on how to do this as most of the somewhat relevant information is focused around converting with the GETDATE option instead of leveraging the date that's already written to the database (the information is entered on a different part of the website).
I'm just looking for a pointer or a suggestion in the right direction to use a SELECT statement in my gridview (along with all of the other fields) that can convert any/all of the entries into one common date format. I know I'm missing something simple here but I don't know what.
I should note that I don't want to change them in the Database just when presenting them in the Gridview.
Use the following Convert SQL Function around all of the date fields you require, be warned that this can cause errors if the value is not a correctly formatted date.
CONVERT(datetime, [OldDate], 112)
Found here.
Also look here for more information on the Convert Function

Setting report to current date

I have a report where it shows meetings and their requirements. However i just want the report to show ONLY today's stuff--not the entire week's worth.
I tried setting my group header (i'm grouping by day) to currentdate but yet it still shows me the entire week. I then have to go to the grouping tree and select today's date. Is there any way to run my report and have it ONLY show today's stuff and nothing else???
Any ideas?
Use the select expert to limit the results to today's date. printdate is a special Crystal Formula keyword.
{table.date_field} = printdate
Or, if you're working with a datetime db field you can strip the time with CDate
CDate({table.date_field}) = printdate
One way would be to change your query so that it's only getting one day's worth of data; that is, assuming your data contains a date field. To take it a step further, you could add date parameters to the query itself and leave the group headers as is. That way, you can have one day of data, or data from a specific date range.
If you have no influence (or desire) to change the way data comes into Crystal Reports, you could also add a formula via the Section Expert to suppress the group or detail section unless the date is the current date.

Resources