I am writing a report that needs to display a different datediff calculation based on a specific Value from a column. If the order is "Active" start time to Now or if the order is ceased start time to stop time.
The individual DateDiff expressions work but when I try to combine them in one expression using either switch or IIF I get errors.
Any suggestions would be great.
=IIF(Fields!OrderStatus.Value="Active", DateDiff("d",Fields!OrderStartTime.Value, "Now"()),
IIF(Fields!OrderStatus.Value="Discontinued", DateDiff("d",Fields!OrderStartTime.Value, Fields!DiscontinueTime.Value)
)
)
=Switch(Fields!OrderStatus.Value="Active",
DateDiff("d",Fields!OrderStartTime.Value, "Now"()),
Fields!OrderStatus.Value="Discontinued",
DateDiff("d",Fields!OrderStartTime.Value, Fields!DiscontinueTime.Value),
)
You are missing the third argument for your second iif statement (in this case, it'll be {Nothing}. This should work:
=IIF(Fields!OrderStatus.Value="Active",DateDiff("d",Fields!OrderStartTime.Value,Today()),IIF(Fields!OrderStatus.Value="Discontinued",DateDiff("d",Fields!OrderStartTime.Value,Fields!DiscontinuedTime.Value),Nothing))
Related
Hello i tried using both switch as well as iif function in ssrs report. I have a column(Delta) which has values and need to set image depending on column values. Below is my switch statement
=Switch(
Fields!Delta.Value =0,"arrowzero.jpg",
Fields!Delta.Value >0,"arrowup.jpg",
Fields!Delta.Value <0,"arrowup.jpg",
Fields!Delta.Value ="CNC","arrowblack.jpg"
)
Switch statement is working for all cases except last case "CNC".
A couple of observations that might help you fix this.
You switch statement uses the same column however the first three evaluate it numerically, the last one against a string. Is this correct?
Is the image called "arrowblack.jpg", is there a typo here?
If the last option is supposed be act like an ELSE then you can replace Fields!Delta.Value ="CNC","arrowblack.jpg" with True,"arrowblack.jpg"
Im trying to find the days gap between two dates using DateDiff function.
I have 2 datasets defined. If companycode is 'AB' then from one dataset else from another dataset I retrieve data.
Here is my expression. When I change to preview mode, it shows redmark to the first First(Fields!PeriodFrom.Value line. Why? (after generating report that field shows #Error
What Im doing wrong here?
=IIF(Parameters!CompanyCode.Value="AB",
DateDiff("d",First(Fields!PeriodFrom.Value, "ABReportData"), First(Fields!PeriodTo.Value, "ABReportData")),
DateDiff("d",First(Fields!PeriodFrom.Value, "XYReportData"), First(Fields!PeriodTo.Value, "XYReportData")))
I think there are two possible scenarios. First one is the expression
=First(Fields!PeriodFrom.Value, "ABReportData")
doesnt return a value. Add a column with this expression and check if you get a value.
If the value is correct, make sure that the DateDiff() function gets a date:
=IIF(Parameters!CompanyCode.Value="AB",
DateDiff("d",
CDate(First(Fields!PeriodFrom.Value, "ABReportData")),
CDate(First(Fields!PeriodTo.Value, "ABReportData"))
),
DateDiff("d",
CDate(First(Fields!PeriodFrom.Value, "XYReportData")),
CDate(First(Fields!PeriodTo.Value, "XYReportData"))
)
)
I'm trying to make a query using a calculation with Date().
I have a field named [Currentordue] and a field named [duedate]. What I'm trying to accomplish is making a query to limit the results by "if [currentordue] equals "due" or if [duedate] minus today's date is less than 30 days."
I've tried a few different ways but always seem to end with either an error or with no results showing (which would be an error as well since I know there are fields that are due).
Any and all help would be appreciated.
Here is a way to use two different date conditions:
SELECT Table1.Currentordue, Table1.duedate, DateDiff("d",[duedate],Date()) AS Expr1
FROM Table1
WHERE (((DateDiff("d",[duedate],Date()))<30)) OR (((Table1.Currentordue)=[duedate]));
I am trying to sort data by the week it was created. I can not use 'w' in DateAdd, 'week' or 'WeekOfYear' without an error stating that function/expression is inaccessible.
What is the best way to create a substitute expression? I want the expression to group the dates based on the week it was created.
I am trying to replicate this:
http://imgur.com/Pk8YjUv
Based on the expected results you posted in the edition of your question I have reproduced the tablix.
I've used the following dataset:
I am supposing you are going to use a tablix component so I added this one with the following data arrangement.
In the Row Groups panel right click on date group.
In group properties, add a group expression and set this:
=DATEADD("d",7-DATEPART(DateInterval.Weekday,Fields!date.Value),Fields!date.Value)
Also in the tablix you have to set the same expression:
In the columns you want to sum you can use the Sum function or any aggregation function. I've used =Sum(Fields!value.Value) to Sum values within the same week.
This is the result it will preview:
Let me know if this was helpful.
In SSRS, I'm trying to calculate the average number of months a client used a program. The programID is the parameter for the whole report. I'm trying to achieve this (not written with real syntax):
=Avg(Fields!length_of_stay.Value, 0))/30.0 WHERE programid = #ProgramID
Using this question, I came up the the following code which is producing an incorrect answer. I tested in SSMS to get the actual values to compare to SSRS results.
=Avg(IIF(Fields!programid.Value = Parameters!ProgramID.Value, Fields!Length_of_Stay.Value, 0))/30.0
The "/30" is used since the value is in days and I need months. I think the issue is using the parameter value chosen; this is my first report trying to calculate expressions with parameters.
Avg returns the average of all non-null numeric values. 0 is not null so it gets included in the average, distorting your result for every row with a different PragramId. Try using Nothing instead:
=Avg(IIF(Fields!programid.Value = Parameters!ProgramID.Value, Fields!Length_of_Stay.Value, Nothing))/30.0