Multiple iif and condition in SSRS expression - reporting-services

I get an error from the below expression in SSRS report. If status is active and month_nbr and year_nbr is greater than last day of status_DT, it will show count_value which is int type. Can you help me fix it? Thanks!
=IIf((fields!status.value="Active") and
(cdate("01"+Fields!month_nbr.Value+Fields!year_nbr.Value)>
DateAdd("d",-1,(DateAdd("m", 1, DateSerial(Year(fields!Status_DT.value),
Month(fields!Status_DT.value), 1))))),Fields!Notes_Count.Value,"9999")

Try replacing:
cdate("01"+Fields!month_nbr.Value+Fields!year_nbr.Value)
by:
CDATE(CStr(Fields!year_nbr.Value)+"-"+CStr(Fields!month_nbr.Value)+"-01")
Let me know if it works.

Related

DateDiff function in SSRS (report server) gives error?

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"))
)
)

SSRS report returning error - The sort expression for the group 'grp' contains an error: Attempted to divide by zero

I am attempting to fix an error in a previous developers SSRS report. There is a group by parameter, when choosing a certain value it returns the error - The sort expression for the grouping 'grp' contains an error: Attempted to divide by zero.
The error suggests this expression is causing the error;
=-Sum(Fields!RentCollected.Value)/Sum(Fields!RentDue.Value)
Selecting other parameters works without any errors.
Any ideas how this can be fixed?
I don't know what further information to provide but can if it specified.
Thanks in advance for any help.
Looks like the error is caused when the sum of Fields!RentDue.Value is zero. To fix this, a simple IIF statement to check for zero should fix the issue. Try the following expression.
=Sum(Fields!RentCollected.Value)/IIF(Sum(Fields!RentDue.Value) = 0, 1, Sum(Fields!RentDue.Value))

How do I find the current quarter in SSRS?

How would I find the Current Quarter in SSRS? I am trying to set a default value for a parameter to the current quarter. I tried:
=QUARTER(NOW)
But it returned the following error:
The Value expression for the report parameter ‘pquarter’ contains an
error: [BC30451] 'QUARTER' is not declared. It may be inaccessible due
to its protection level.
As of the writing of this post 6/20/2018 I am trying to return 2.
In SSRS:
DatePart(DateInterval.Quarter,Fields!date_var.Value)
Quater is a date related and this should work.
select DATEPART(Q,GETDATE())
I was able to find the following function:
=DatePart("q",NOW())
It seems to work.

SSRS standalone formulas

I have been working on this for days without being able to solve yet. It's probably simple if you know what you're doing. I'm simply trying to make a standalone formula that is not in a tablix or anything, it's just in a textbox.
Here is an example of my Dataset called Dataset1:
What I am trying to get is a sum of the Actual Cost when the Category is Labor from Dataset1. My current expression is:
=Sum(iif(Fields!Category.Value="Labor", Fields!ActualCost.Value, 0), "Dataset1")
I refer to Dataset1 as my scope because otherwise, I get an error about using an aggregate expression without a scope.
The report runs but shows #Error in the textbox that has my expression in it. When I replace Fields!ActualCost.Value with a 1, I get the answer, 5, which is the correct number of rows with Labor as the Category. But it won't let me sum the numbers in the ActualCost column where Category is Labor.
Any ideas as to what I'm doing wrong? I feel like it's something to do with aggregating, but I'm not sure. Thanks!
It may have to do with the datatype of fields!ActualCost.Value. If that field is a decimal (regardless of how you have it formatted), try using cdec(0) instead of just 0 in your expression.

Expression for getting total value of a field etc

I need help for the following
1) Could you give me expression for getting total of a field in SSRS
2) My date saved in database is mm/dd/yy, when shown in report, I want to show it like May 21, 2011, How?
Thanks a lot.
Furqan
1) =Sum(Fields!YourField.Value)
2) =Format(Parameters!DateField.Value,"MMM dd,yyyy")
This answer your questions?