I am trying to Subtract two scenarios from each other in a SSRS report. One scenario is a constant, 'Actuals' the other is a dynamic forecast scenario and set by a parameter. Here is the code I am trying:
=sum(iif(Fields!Scenario_Name.Value=Parameters!ScenarioName.Value,CDbl(Fields!CAD.Value),0))-
sum(iif(Fields!Scenario_Name.Value="Activity Actuals",CDbl(Fields!CAD.Value),0))
I have also tried:
=sum(iif(Fields!Scenario_Name.Value=Parameters!ScenarioName.Value,Fields!CAD.Value,0))-
sum(iif(Fields!Scenario_Name.Value="Activity Actuals",Fields!CAD.Value,0))
The report runs but I get an error in the line where this expression is entered.
The CDEC was important to both the CAD.value and the 0. The Parameter value needs a (0) as in the final expression that works.
enter code here=Sum(IIf(Fields!Scenario_Name.Value=Parameters!ScenarioName.Value,CDEC(Fields!CAD.Value),CDEC(0))) -
Sum(iif(Fields!Scenario_Name.Value="Activity Actuals",CDEC(Fields!CAD.Value),CDEC(0)))
Related
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"))
)
)
User enters a fixed parameter representing a Credit Limit.
Then each row subtracts a different column called [AmountPaid].
So the Balance Available column show what is left and this gets smaller and smaller down the rows to the bottom.
Both column textboxes in Tablix are set to Number type=Currency. Parameter is set to Float. Not many choices of data type for the Parameter input.
I thought this would work in an expression for the Balance Available but it gives me an error. My idea was to do a running Sum and then subtract it from the initial Credit Limit:
=Parameters!CreditLimit.Value - RunningValue(Fields!AmountPaid, Sum, "DataSet1")
The message for the error is:
[rsAggregateOfInvalidExpressionDataType] The Value expression for the textrun ‘Textbox23.Paragraphs[0].TextRuns[0]’ uses an aggregate function with an expression that returned a data type not valid for the aggregate function.
If this question could be asked differently I am open to suggestions. Thanks
You need to get the value of AmountPaid so try Fields!AmountPaid.Value`
Sorry for very basic question,
I have SSRS report which takes value of parameter dynamically and creates MDX query.
Now, I have that MDX query and I want to run in SSMS or MDX studio. But I am not sure how to replace the parameter value.
For example:
WITH MEMBER [Measures].[HC Threshold] AS Val(strtomember(#HC_Threshold).Name), FORMAT_STRING="$#,0"
And I found HC_Threshold dimension, which looks like
based on this, how do I modify 'Val(strtomember(#HC_Threshold).Name), FORMAT_STRING="$#,0"', if user selects 75000.
Let me know if you need any more information, I am completely new with SSRS and Parameterized queries in MDX.
Thanks
Replace the parameter value for a string that produces a valid member of your dimension.
select [Product].[Model Name].[Model Name] on rows,
[Measures].[Sales Amount] on columns
from [Adventure Works DW2012]
where STRTOMEMBER("[Ship Date].[Calendar Quarter].[4]")
Note STRTOMEMBER() receives a string as argument and converts it to a valid member.
In your scenario it would be something like:
STRTOMEMBER("[HC_Threshold].[ID].[7500]")
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
My dataset currently has 12 rows of data. Each representing data for a month. I would like to have variance of a column between to rows, the rows being last & last but one i.e., latest month and previous month's data.
It could have been simple if I were to work on tablix but thats not the case. I want those values for a textbox.
Any ideas on it anyone?
I hope you are using SSRS 2008R2:
R2 introduced the Lookup function that is perfect for this scenario.
=Lookup( Fields!ProductUID.Value ,Fields!ProductID.Value,Fields!Price.Value,"PriceDataSet")
The Lookup function above will evaluate the first parameter ("Fields!ProductUID.Value") in the current dataset, then look for a matching value in the field specified in the second parameter ("Fields!ProductID.Value") in the dataset specified in the fourth parameter. The value of the third parameter is then evaluated in that row of the dataset and returned.
A little convoluted, but very helpful.
In your case, you can use this in a textbox with a calculated a static number:
=Lookup(
Month(DateAdd(DateInterval.Month, -1, GetDate())),
Fields!MonthID.Value,
Fields!Name.Value,
"DataSet1")
This should calculate a number for last month, then look for a match in DataSet1.
In this example I have a tablix with Statecode and name as below
enter image description here
Suppose you want to display the name of state of CA, write an expression as -
=Lookup(
"CA" ,
Fields!StateCode.Value,
Fields!StateName.Value,
"ReportData"
)
This will return 'California' in the text box
I ran across this post while trying to solve a similar problem but with columns of double data type. Not sure why but SSRS did not want to return my first row using LOOKUP in combination with ROW_NUMBER in SQL(If someone can solve that all the better). I ended up using a SUM(IIF) instead. Hopefully, this is useful for someone else.
=Sum(IIF(Fields!RowNum.Value=1,CDBL(Fields!MyNumericColumn.Value),CDBL(0)))
Note: If SSRS complains about data types, just cast both parts of the IIF to the desired data type.