SSRS-Reports formatting - reporting-services

I am having a few issues using SSRS-Reports 2005.
The first one is I am trying to use the datediff function to change the background color of a cell based on the two dates being within 30 days of each other.
=iif(
DateDiff("d",DateString,Fields!Insurance_Certificate.Value)<= 30, "Tan", "White"
)
I have my fields formatted through the initial query so they look like mm/dd/yyyy. I guess my first question is how do I see what value is being evaluated because whatever this is returning can't be right.

my [...] question is how do I see what value is being evaluated
There is no real "debugger" available like you would have in -say- a WinForms C# app. Instead, you have several "raw" "debugging" options:
Render Fields!Insureance_Certificate.Value in a seperate cell, as text
Render DateDiff("d",DateString,Fields!Insurance_Certificate.Value) in a seperate cell, as text
Right-click your dataset, select "Query...", and execute the query manually. Inspect the values for your field. Make sure they're what you'd expect.
Render your DateString in a seperate cell, with and without a cast to a date.
Other than that #MarkBannister has a great suggestion, using actual Dates as opposed to strings for your fields and variables. One additional thing to note about this, is that date parsing may be culture-specific. Be sure you understand and know in what culture your DateString is being parsed. The above "debugging" options may help you find out.

I suggest querying your date fields as dates (instead of as strings), comparing them using the DateDiff function as in the question and formatting the date output using the Format property of the appropriate textboxes in SSRS.

Related

In SSRS, how to include first row from different dataset in tablix?

I am creating a report, the purpose of which is to print a letter to many different people. Obviously each person's name, email, etc. will be different. For this I am using a list, which I understand uses a tablix.
Now inside each letter I also need some global data that comes from a dataset. For example, the company email, telephone number, etc. This data will be the same for every letter. However, every time I try to use some expression to get this, I get an error such as:
The Value expression for the text box ‘Textbox11’ refers to the
field ‘URL’. Report item expressions can only refer to fields within
the current dataset scope or, if inside an aggregate, the specified
dataset scope. Letters in the names of fields must use the correct
case.
The expression I'm using to get the above error is
=LookupSet(true, true, Fields!URL, "SystemVars")
I've tried other things but I can't figure out what I need to make it word.
Is there an expression I can use to solve this problem? If not, what steps should I take to get my letters working?
You are missing the ".Value" portion in the expression. Try this:
=First(Fields!URL.Value, "SystemVars")

SSRS chart series labels: Field!axisfield.Value not current value

I am trying to dynamically format the labels on my SSRS charts based on the underlying value. I'm trying to do this in two scenarios, one to format dates as ordinals and another to choose the appropriate number of decimal places based on actual values present. However, when I use the expression editor with an expression something like this...
=IIF(MAX(ABS(Fields![axisfield].Value))<2, "0.0%","0%")
...the Fields![axisfield].Value is always returning the first value from the dataset, meaning, in this example, if the first value is less than two, the labels will be formatted with one decimal place, even if it is the only one less than two. (So the 'MAX' function is essentially irrelevant.)
That example is attempting to set the overall formatting based on the largest data point in the series, in this next one I'm trying to format each label separately to get Ordinal dates (i.e. 1st, 2nd, etc, and yes, this formula is incomplete: it doesn't need to be to illustrate the problem):
="dd"+IIF(DatePart("d", Fields!date.Value)=1,"\s\t"
,IIF(DatePart("d", Fields!date.Value)=2,"\n\d"
,IIF(DatePart("d", Fields!date.Value)=3,"\r\d"
,"\t\h")))
This will give 1st, 2st, 3st and so on, as the first row in the dataset is for the first.
So, my question is, how do I get round this and, in the first example get the true maximum, and in the second reference the actual value being formatted?
Thanks!
I've had the same issues with using custom functions for setting label visibility. (see my entry for this: How to Display Only 1 Value Label in SSRS 2012 Calculated/Derived Series? )
I believe the issue is that data and fields are bound to the underlying data series but are not bound and accessible within the label itself.
You should be able to set the formatting in the function for the series data itself (as in the 2nd example) and then just set data labels, which will use the underlying series field value. An example with your data might be something like the following, which returns the values with the format:
="dd"+IIF(DatePart("d", Fields!date.Value)=1,Format(Fields!date.Value, "\s\t")
,IIF(DatePart("d", Fields!date.Value)=2,Format(Fields!date.Value,"\n\d")
,IIF(DatePart("d", Fields!date.Value)=3,Format(Fields!date.Value, "\r\d")
,Format(Fields!date.Value,"\t\h"))))
In the first example, you can get the max value to referring to the Dataset, as opposed to the field. Your code would then be:
=IIF(ABS(MAX(Fields![axisfield].Value, "YourDatasetName"))<2, "0.0%","0%")
(I changed the order of operations for Abs and Max because you have to use an aggregate function when referring to the whole dataset. Only then can you refer to the specific value.)

SSRS datetimepicker and textboxes behave differently when using Weekday function

In my SSRS report i have a date parameter and i want to set to it a default value with a complicated logic. I arrived at this strange behaviour:
Today is May 6th, wednesday. If i use the following expression:
DateAdd("d",Weekday(Today(),DayOfWeek.Sunday),Today())
for the default time picker I get May 9th.
If I use exactly the same expression in a textbox in the same report
DateAdd("d",Weekday(Today(),DayOfWeek.Sunday),Today()).ToLongDateString()
I get May 10th!
The only thing that changes is the toString.
Why are the two values different?
I tried with different expressions and the difference arises when i start using Weekday(Today(), somevalue)
After a while and some fundamental help i realized that I had to use "FirstDayOfWeek" instead of "DayOfWeek" in both expressions for both of them to be the same regardless of current culture.

MS-Access Web DB "type mismatch" when setting date as string?

This is specifically for MS-Access Web Databases (requires Sharepoint hosting) which has many limitations compared to their client counterparts, like no VBA, instead you get form macros and data macros to manage data.
I've run into a weird bug on one of my applications. I have a query used to check stock levels against a "minimum stock level" also saved in the table. The query is pretty intense and there are over 4,000 records now to check against. These querys normally take about 75s. So I have made a little label that gets updated every time the form is loaded showing the time and date the query was last run, and the duration in seconds it took. (so users can see how fresh the data is and decide if it needs to be run again)
Now, the weird thing is it works fine in my Access client, but when I sync my changes to the server and try it in a web browser I get a "type mismatch" error. A small table is used to store the start and end times whenever the query is run, that's how I get the timestamp data. These fields are in a "Date/Time" format, obviously. But it seems the problem here is changing the date format to a string format so it can be put in a label on the form. The Access client seems perfectly capable of doing this, while the web client stumbles and falls.
My problem is, how do I change data in a date/time format to a string format in a Web database? I can't figure out how to do this. The tools are so limited. I may have to end up answering my own question here but I'm posting this for others just in case.
To return a value from a data macro as string, you have to format the internal date/time format as a string. In Access an internal date/time value is a double number with the integer part as number of days since 1900, and the “decimal” time part is a fraction of 24 hours. Unfortunately if you simply wrap the date/time in the str$() function we had for 20+ years, then you get something JUST like if you type this into the debug window:
? cdbl(now())
41955.5478587963
The solution is to simply pull out each part. And “nice” is while in few cases a data macro will cast the data type, it does in this case and thus the STR$() command is not required.
The expression you thus can use is this:
Month([d]) & "/" & Day([d]) & " Time = " & Hour([d]) & ":" & Minute([d])
So say to pluck out the VERY LAST start time column from say a invoice table, since we don’t have a dmax(), then we simply sort the table in the order we want and pull out the first row.
Our data macro will thus look like:
Note how in above I simply typed in the SQL and SET the order on the date/time column. I want the MOST recent invoice start date and time. For those new to SQL, then I suggest you build a query in the query builder and specify a query in above lookup feature, since many are not "comfortable" typing in free hand SQL as I did above.
Now, in your browser side (UI) macro, you can use this code:
The above returns a formatted string that you can stuff into a text box, or as per above code change the caption of a label.
Unfortunately with silly problems like this, it becomes a path-of-least resistance thing.
Since my intended result was simply to get "a timedatestamp from a table to show up on a form (so users could see when a query was last run)", this became redesigning my form in Access to be a text field instead of a label. Text fields can be adjusted to accept "Time/Date" formats, so this is exactly what I did, it now pulls the timestamp data directly from the last record of the table and requires no extra formatting to appear in the web browser. I redesigned the text field to appear and function more like a label, and my desired function was achieved.
However, since my question specifically asks, "how do you change a time/date format into a string format in a Web db?", I will leave it here in case someone actually does solve it.

Use a summary field in an expression in SSRS reports

I have the details of my report being summed up in a summary expression, all works fine. The fields are decimal values of hours worked. Thus, the summary value is also a decimal value. I'd like to access the summary value and convert it to hours / minutes. I've labeled the express as "WorkTimeSum", but can't seem to get a handle to it, however. Fields! obviously won't work since it is a summary expression. I was thinking ReportItems! should work, but to no avail. How can I use this expression field (in a summary row) in an expression in the same summary row?
If I've understood correctly, you're asking how to reference the textbox containing the total work hours value so that you can convert it to hours and minutes using an expression in a different textbox?
You can use either ReportItems! e.g.
=ReportItems!Textbox20.Value)
or ReportItems("") e.g.
=ReportItems("Textbox20").Value
to reference the value of another textbox. Be careful with the names as they are case sensitive.
You can use aggregate functions in any expression. For example, in any header rows you can use the following expression to determine the total hours value:
=Floor(Sum(Fields!hours.Value))
Sum(Fields!hours.Value) is just the total hours in whatever context, e.g. the group total if it's a group header row; you can use this expression as an input in any other expression you require.
It sounds like your issue wasn't the conversion itself, so hopefully this points you in the right direction. If you need further information please specify.