Summation Error (SSRS) - reporting-services

From the image above, I want to sum the Time Spent column in my SSRS report. The issue is that this is not an int column but a varchar (after finding the difference between two datetime columns). I want my result set to be in the format - 00:00:00 (form of hh:mm:ss).
The sql query looks like:
CONVERT(Varchar(10), Dateadd(Second, DATEDIFF(Second,StartDate,FinishedDate),0), 108) AS SpentTime
What do I have to do to get the right values back?
Thank you.

Instead of using VARCHAR formatting in the SQL procedure, you can send the TimeSpent as a time data type and then you can use the expression below. You can then format the time within the report itself instead using text box properties.
=TimeSpan.FromTicks(Sum(Fields!TimeSpent.Value))

Related

Dynamically change column names as week number on every weekly run

I want to build a SSRS report that has column as week numbers - 8 weeks for 8 columns starting with current. This report is run every week and current week number is set then. So both column names and their values should change .Is it possible to build something like this in SSRS?
I tried doing this with a dynamic SQL based stored proc in dataset. However for every run I don't even see the columns values updating dynamically
Here's an example :
Also I am trying to avoid these week numbers as row values and then using matrices
My stored proc looks something like this
declare #n tinyint = datepart(wk, getdate())
declare #n1 tinyint = (#n+1), #n2 tinyint =(#n+2), #n3 tinyint =(#n+3), #n4 tinyint =(#n+4), #n5 tinyint =(#n+5), #n6 tinyint =(#n+6)
exec ('Select b.sku, b.['+#n+'], b.['+#n1+'], b.['+#n2+'], b.['+#n3+'], b.['+#n4+'], b.['+#n5+']...
Will appreciate any help in this direction.. many thanks!
When working with SSRS it's generally best to avoid dynamic SQL and pivoting the data in the SQL. Use the SQL to get the raw data you need and then let SSRS do the pivoting and aggregation. This way you take advantage of what they each do best. I know you said you want to avoid matrices, but it is the best way to make the report dynamic.
So you should either return all the data in one dataset and use filters on your matrices OR write two queries and have each one populate a matrix. BTW a matrix is just a table with a column group added, so don't be intimidated by them.
There are 2 ways to do this with a standard tablix.
Calculate the column headers as expressions using concatenation of Wk and some date math to find the correct week number and return the same sort of thing from your query (e.g. columns are current_week, week_minus_1, week_minus_2...)
Return the column headers as additional columns in your query that are the same value for every row (e.g. ColHeader0, ColHeader1...). Your data columns would still be relative weeks (e.g. ValueWeek0, ValueWeek1...). In your report the column header would have an expression like =First(Fields!ColHeader0.Value). This is a more flexible approach since it lets you pick 8 historical weeks instead of only the last 8 weeks if you add a parameter.
EDIT - Clarifications
The reason that you get the blank column Wk48 is approximately that you have created your report looking for that column that won't be there the next time. SSRS looks for exact columns. You should you use relative column names for either of the options I have specified:
exec ('Select b.sku, b.['+#n+'] as Wk0, b.['+#n1+'] as Wk1, b.['+#n2+'] as Wk2, b.['+#n3+'] as Wk3, b.['+#n4+'] as Wk4, b.['+#n5+'] as Wk5...
This will allow you to populate the aliased Wk0 column with the appropriate current week data and still make sure that it can be consistently referenced as the base week by SSRS.
To change the column headers you can:
Independently calculate the week numbers in SSRS in the column header expressions: ="Wk" + CStr(<correct week calculation>).
Return the column headers in the result set and access them in the column header expression:
exec ('Select b.sku, b.['+#n+'] as Wk0, b.['+#n1+'] as Wk1, b.['+#n2+'] as Wk2, b.['+#n3+'] as Wk3, b.['+#n4+'] as Wk4, b.['+#n5+'] as Wk5..., ''Wk'''+#n+' as ColHeader0, ''Wk'''+#n1+' as ColHeader1...
and reference the returned column headers from the SSRS column header expression as =First(Fields!ColHeader0.Value).
Here's a solution that worked for me:
Create parameters (say CurrWk, CurrWk1) ,set as hidden and store 'Default value' and 'Available value' equals to current week number (datepart(wk, now()) and any subsequent week by doing a +1, +2, +3.. etc.
Write a query expression . Click onto fx beside dataset query space and write the select query for your program embedding parameter values in the expression window. For eg ="Select SKU, [" & Parameter!CurrWk.Value & "] as Wk1,
[" & Parameter!CurrWk.Value & "] as Wk1 from Sales_Table"
Before passing this query as a 'command text expression' please ensure this query is working in sql ssms.
Save the expression. Now find 'Fields' tab on the left hand side panel.You need to map the fields manually from the query here. If this is not done, there is a very high chance you seean empty field list and wont be able to access them at all. This may be because ssrs do not store query metadata directly from expressions.
You can avoid part of the issue by having atleast the static fields , for example here SKU listed in the 'Fields' list by first running a sql query with static field(select SKU from Sales_Table ). You can then go back to update dataset- change query to expression and embed the parameterized field names.
Map field names. In this example I chose 'Query Type' fields and set Field names as SKU, CurrentWeek, NextWeek and mapped to source SKU, Wk and Wk1 respectively.
Click on 'Refresh Fields' at the bottom. Now you have a dataset with the complete field list. Use these in charts, tables . Run it every week and note the numbers changing as expected.
In case you are using this dataset in a table, make sure you set headers with Labels of Parameters (for eg here I did =Parameters!CurrWk.Label for col with current week data)
That's it!

MS Access Convert text to shortdate

Hi all i have a question,
I have a field in the table whereby its a text field and i want to convert it to date field. Though all the values within are in date format however its not convenient to change because of some circumstances.
Thus i need to change the text field to date field so as to do a comparison or validation.
Im using MS access SQL for this project so please help me
I have tried
TRANSFORM Count(Registrants.[Field1]) AS CountOfField1
SELECT Registrants.[Country] , Count(Registrants.[Field1]) AS [Total Of Field1]
FROM Registrants
WHERE Cast(Registrants.Field1 As Date) Between #15/6/2014# AND # 30/8/2014#
GROUP BY Registrants.[Country]
PIVOT Format([Field1]);
Cast does not exist in MS Access sql.
Use DateValue instead :
WHERE DateValue(Registrants.Field1) Between #15/6/2014# AND #30/8/2014#
See here for sample usage and syntax.
Also I noted a space in your 2nd date, I assume that's a typo.

SSRS Espression for String to Date Time format

Hi I have a SQL Stored Procedure to for my SSRS Report.
Below is the query to fetch Date i used.
(CONVERT(CHAR(10), ENTER_DT, 103), '''')
I am not in a position to change this query. The Dat Format currently displayed is "DD/MM/YYYY".
I want to display the date format as Below using SSRS Expressions.
MM-DD-YYYY
Please guide me to do that using SSRS Expresions. PLease help.
Just change the Display Format instead of converting into TSQL (Stored Procedure), Follow the steps go to textBox Properties, Select Number & Category Custom then Custom Format whatever you want

dd/mm/yyyy date format in SSRS

i'm trying to specify dd/mm/yyyy dateformat for date/time parameter in SSRS 2008 R2.
My computers datetime format is mm-dd-yyyy.
My requirement is, i want to show date format at dd/mm/yyyy irrespective of the system/server date format.
I've already tried CDate(Format(Today,"dd/mm/yyyy")) which didn't work. one very strange thing i observed is, it shows dd/mm/yyyy format only for dates on or before 12-MM-yyyy, and 13 onwards it gives error: Conversion from string '25-04-2014' to type Date is not valid. (Possibly it is trying to map 25(daypart) with MM-dd-yyyy (month part)) which is out of range of total months i.e. 12)
my research on internet says it is a bug in BIDS 2008.
What do i do to display date as dd/mm/yyyy ??
I don't have enough reputation to comment, but I did notice that you failed to put "()" after "Today". If I'm not mistaken you must put Today() for that function to work. Also, you might want to try putting CDate Around the Today() function. You shouldn't need it, but it's worth a shot. Also, for some odd reason, in my experience, you must capitalize MM for format to work correctly.
Like #Aditaya said, it should be =format(Today(),"dd/MM/yyyy")
The expression I usually use is:
=FormatDateTime(Fields!Date.Value, DateFormat.ShortDate)
However, this may be region specific.
Rather than writing an expression to do the formatting, you can also use the Textbox Format Property. But first you need to make sure that the data is in a date format. So use the CDate function on your column like this:
=CDate(Fields!Date.Value)
Then in the textbox properties go to the Number tab. Select Date for the category. Then you can select whichever format you want or use a Custom format. This will change how the column displays when you run the report.

Removing the timestamp from a date in an Excel pivot table connected to a cube

So I have a cube created in Analysis Services 2008 R2. The cube has some dates on one of the non time dimensions. When I put the date on the filters in the excel pivot table, it always puts the date as, for example, 01/18/2012 00:00:00.000. Is it possible to exclude the timestamp from it? I tried using the format cell in excel, but it does nothing to it. I also tried converting from the source (The source is a view from a SQL Server database) from datetime to date using Convert(date,fieldWithDateInfo), and that drops the timestamp, but then Excel treats the field as string, and then the filters start acting really funky. Any suggestions?
check the "format string" property for the attribute...I believe the "shortdate" option is what you want.
Add a calculated column to your time dimension using the code below
CONVERT(Varchar, [YOUR DATE COLUMN], 103) AS Date_UK
and change the 'Name Column' attribute to your new calculated column for the datetime dimension attribute