I have the following error which I can't understand from my expression.
=IIF(IsNothing(Fields!month.Value),"6mr",LEFT(Format(DateValue(MonthName(Right(Fields!month.Value, 2))
+ "," +
Left(Fields!month.Value,4)), "Y"),3) + " '" + RIGHT(Format(DateValue(MonthName(Right(Fields!month.Value, 2))
+ "," +
Left(Fields!month.Value,4)), "Y"),2))
This works perfectly without the IsNothing element.
I have tested the IsNothing element and that works in the following case:
=IIF(IsNothing(Fields!month.Value),"6mr",0).
Help to correct much appreciated.
You are experiencing this "issue" because Reporting Services evaluates both sides of the Iif.
This is not really an issue, it is by design, see this technet article for more details:
SSRS - IIF function evaluates both True & False
Yes , By design the SSRS evaluates both True & False statements even
though the condition is not satisfied and through error if something
is not right.
Now, to get your expression working, you have to consider that Fields!month.Value could be nothing even in the false part of your expression.
So in your expression, you could just replace
Fields!month.Value
by
Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value)
Here is an expression with this fix:
=Iif(IsNothing(Fields!month.Value),"6mr",Left(Format(DateValue(MonthName(Right(Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value), 2))
+ "," +
Left(Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value),4)), "Y"),3) + " '" + Right(Format(DateValue(MonthName(Right(Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value), 2))
+ "," +
Left(Iif(IsNothing(Fields!month.Value), "1", Fields!month.Value),4)), "Y"),2))
You could also create a custom function or use a variable if you want to reduce the expression length.
Related
I am trying to pass a hyperlink in SSRS to open a new SSRS report (in pdf) from a text box. It is currently set up and works passing a single parameter :
="http://servername/ReportServer_REPORTS16/Pages/ReportViewer.aspx?%2fdummy%2fDocuments%2fCertificate+of+Insurance+Issued&rs:Command=Render&PolicyNo="
& Parameters!PolicyNo.Value &"&rs:Format=PDF"
However when I add in the second parameter :
="http://servername/ReportServer_REPORTS16/Pages/ReportViewer.aspx?%2fdummy%2fDocuments%2fCertificate+of+Insurance+Issued&rs:Command=Render&PolicyNo="
& Parameters!PolicyNo.Value &"&
Entitled="&Parameters!Entitled.Value &"&rs:Format=PDF"
I get an error message :
The ActionInfo.Action.Hyperlink expression for the text box
‘Textbox48’ contains an error: [BC30277] Type character '&' does not
match declared data type 'Object'.
I've gone through every similar error I've found on google but cant work out where im going wrong.
You need to convert all your values to strings then use the + operator....
Here'a an exmaple from one of my reports that does the same thing.
=IIF(Fields!PackSizeDesc.Value = Nothing, Nothing,
"http://MyServername/ReportServer?/Brand+Value/_sub+SKU+Price+Details"
+ "&CountryID=" + cStr(Fields!CountryID.Value)
+ "&CategoryID=" + cStr(Fields!CategoryID.Value)
+ "&RecordedPeriodID=" + cStr(Parameters!PeriodID.Value)
+ "&TMB=" + cStr(Fields!TrademarkBrandID.Value)
+ "&PriceStage=" + cStr(IIF(Fields!IsActualprice.Value = 1, 10, 11))
+ "&pm=" + cStr(Fields!PackMaterialID.Value)
+ "&pt=" + cStr(Fields!PackTypeID.Value)
+ "&ps=" + cStr(Fields!PackSizeID.Value)
+ "&psu=" + cStr(Fields!PackSizeUnitID.Value)
+ "&upp=" + cStr(Fields!UnitsPerPack.Value)
+ "&rc:Parameters=Collapsed")
Note: The first line just disables the link if there is now value in a particular column. This does not render to PDF but that's not part of your issue.
I'm trying to use conditional formatting in SQL Server Reporting Services to change the colour of a row if a value is the same as today's date or not. The column contains the date in the format 13/07/2018. I have also set the field to be in date format (31/01/2000) within place-holder properties.
My expression however is not working
=switch(DateDiff("d", Fields!LastSuccessfulBackupTime00.Value,Format(Now(),"dd/MM/yyyy")) = 0, "Green",DateDiff("d", Fields!LastSuccessfulBackupTime00.Value,Format(Now(), "dd/MM/yyyy")) = 1, "Yellow",DateDiff("d", Fields!LastSuccessfulBackupTime00.Value,Format(Now(), "dd/MM/yyyy")) >= 2, "Red")
The exception that is being thrown is
Argument matching parameter 'DayOfWeek' narrows from 'String' to 'Mcrosoft.VisualBasic.FirstDayOfWeek'
Which is strange because I'm just doing simple datediff calculation to count the number of days between two dates.
Can anyone suggest how to fix this ? Google just says to turn off strict compilation something which I can't find in SQLRS
Try the expression below (expression 1)
=switch(
DateDiff("d", Cdate(Fields!LastSuccessfulBackupTime00.Value),Today()) = 0, "Green"
,DateDiff("d", Cdate(Fields!LastSuccessfulBackupTime00.Value),Today()) = 1, "Yellow"
,DateDiff("d", Cdate(Fields!LastSuccessfulBackupTime00.Value), Today()) >= 2, "Red"
)
Also because Cdate is regional setting dependant you could use Split to create a valid date format for datediff (expression2)
=switch(
DateDiff("d", Fields!LastSuccessfulBackupTime00.Value.Split("/")(2) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(1) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(0),Today()) = 0, "Green"
,DateDiff("d", Fields!LastSuccessfulBackupTime00.Value.Split("/")(2) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(1) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(0),Today()) = 1, "Yellow"
,DateDiff("d", Fields!LastSuccessfulBackupTime00.Value.Split("/")(2) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(1) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(0),Today()) >= 2, "Red"
)
I want to display records in MS SSRs based on multiple IFFs Condition. Any idea? Please help me!
My table is "customers" and columns are "cust1", "cust2", "cust3", "cust4"
if(cust1.value!=null)
{
display cust1;
if(cust2.value!=null)
{
display cust1+","+cust2;
}
if(cust3.value!=null)
{
diplay cust1+","+cust2+"and+"+cust3
}
if(cust4.value!=null)
{
diplay cust1+","+cust2+","+cust3+"and"+cust4;
}
}else
diplay cust1;
I just wrote C# syntax for understand logic. I want to display like result
Ex: for SSRS I tried
=First(Fields!cust1.value,"customername")&
IIF(First(Fields!Cust2.value,"customername")+" ">" ",
IIF(First(Fields!Cust3.value,"customername")+" ">" ",
IIF(First(Fields!cust4.value,"customername")+" ">" ",
", "+First(Fields!Cust4.Value,"customername")+
", "+First(Fields!Cust3.Value,"customername")+
", "+First(Fields!Cust2.Value,"customername"),
" and"+First(Fields!cust1.Value,"customername"))," ")," ")
but no idea how to implement "cust2", "cust3". Any help?
This is how the IIF expression works.
IIF( CND , DWT , DWF )
CND = The condition that is checked:
In your example: Len(First(Fields!cust1.value,"customername")) > 0 (or IsNothing(First(Fields!cust1.value,"customername")) but then you need to turn it around)
DWT = What to do/display when true. So when the condition is met.
In your example you wish to display the value.
DWF = What to do/display when false. Familiar to the "else" part of an if-block.
In your example you wish to display nothing or an empty string.
If you actually want to nest multiple IIF expressions it is possible by just replacing a DWT or DWF (or both) with another IIF expression. This can be nested as many times as you desire. Here is a simple example:
IIF( CND1 , IIF( CND2 , DWT2 , DWF2 ) , IIF( CND3 , DWT3 , DWF3 ) )
------------------|________DWT1________|---|________DWF1________|---
However, when applied on your example I don't believe it is necessary to nest. The following expression should give you the desired result:
=IIF(Len(First(Fields!cust1.value,"customername")) > 0, First(Fields!cust1.value,"customername") + " ", "") +
IIF(Len(First(Fields!cust2.value,"customername")) > 0, First(Fields!cust2.value,"customername") + " ", "") +
IIF(Len(First(Fields!cust3.value,"customername")) > 0, First(Fields!cust3.value,"customername") + " ", "") +
IIF(Len(First(Fields!cust4.value,"customername")) > 0, First(Fields!cust4.value,"customername"), "")
I have a nvarchar cell with some number as is : 12345678, and I would format it like this : 12-345-678. But I'm unable to find the right expression...
Should I do this in TSQL before inserting it in the report ?
I'm using SSRS 2008
You can do this in either T-SQL or an SSRS expression.
T-SQL:
declare #value nvarchar(8);
select #value = '12345678';
select formattedValue = left(#value, 2)
+ '-' + substring(#value, 3, 3)
+ '-' + right(#value, 3);
SSRS expression:
=Left(Fields!value.Value, 2)
& "-" & Mid(Fields!value.Value, 3, 3)
& "-" & Right(Fields!value.Value, 3)
This assumes a fixed length text.
It's really up to you which is better - I suppose one consideration would be to keep the formatting at the presentation layer, i.e. SSRS, so that's probably the way I would go. But nothing stopping you using either option.
I am writing an SSRS report in which my client wants the report header to contain the criteria on which the report is based (actually, this is the report variables, such as date).
I tried to do this with textboxes, but can't seem to position the textboxes in such a way that upon export to excel there aren't crazy cell merges.
I also tried to do this with a table in the report body, but got the variable added to each line of the report.
I don't see a position property, as if I was working in just a web form, but am at a loss as to what to do. Any suggestions? Thanks!
Cell merges are a fact of life when exporting to Excel unfortunately, that's how the report rendering engine tries to maintain fidelity with the original report design. The best way to minimise this is to ensure the edges of the report elements align with each other as much as possible, so that the renderer can align the report without having to merge cells.
What you are doing by putting textboxes in the report header to display the value of selected report parameters is a good approach that is commonly used, so keep experimenting with the layout to get it to align correctly.
If you can describe what is happening when you export the report in a bit more detail I might be able to offer some more advice.
In my reports, I add an additional table at the end of the report and assign a page break before the tablix. In the large, single-cell table, I write sentences using quoted text, built-in fields, and parameter values to list all of the parameter information. I label the Name of the Tablix "Parameters" so when the report is downloaded, all of the parameter data goes with it in a nice, non-invasive format. When troubleshooting reports this has proved very valuable.
Here's an example:
=Globals!ReportName + " run by " + User!UserID + " on " + FormatDateTime(Globals!ExecutionTime, DateFormat.ShortDate) + ". "
+ vbcrlf +
"Parameters: " + "Program ("+Parameters!BusinessEntityID.Label+ "), Deliverable Status Code (" + Join(Parameters!DeliverableStatusCode.Label, ", ") +
"), Science Area (" + Parameters!ScienceAreaID.Label + "), Thrust Area (" + Parameters!ThrustAreaID.Label + "), Center (" + Parameters!CenterID.Label + ") "
+ IIF(Parameters!TaskActiveFrom.Value is Nothing, "", ", Tasks Active between "+ FormatDateTime(Parameters!TaskActiveFrom.Label, DateFormat.ShortDate)
+ " and " + FormatDateTime(Parameters!TaskActiveTo.Label, DateFormat.ShortDate))
+IIF(Parameters!TaskStartFrom.Value is Nothing, "", ", Tasks Started between " + FormatDateTime(Parameters!TaskStartFrom.Label, DateFormat.ShortDate)
+ " and " + FormatDateTime(Parameters!TaskStartTo.Label, Dateformat.ShortDate))
+ IIF(Parameters!DeliverablePlannedFrom.Value is NOTHING, "", ", Deliverable Due Date between " + FormatDateTime(Parameters!DeliverablePlannedFrom.Label, Dateformat.ShortDate)
+ " and " + FormatDateTime(Parameters!DeliverablePlannedTo.Label, Dateformat.ShortDate))
+ IIF(Parameters!DeliverableExtendedFrom.Value is Nothing, "", ", Deliverable Revised Due Date between " + FormatDateTime(Parameters!DeliverableExtendedFrom.Label, Dateformat.ShortDate)
+ " and " + FormatDateTime(Parameters!DeliverableExtendedTo.Label, Dateformat.ShortDate))
+ IIF(Parameters!PublicationReceivedDateFrom.Value is NOTHING, "", ", Publication Received Date between " + FormatDateTime(Parameters!PublicationReceivedDateFrom.Label, Dateformat.ShortDate)
+ " and " + FormatDateTime(Parameters!PublicationReceivedDateFrom.Label, Dateformat.ShortDate))