I hope someone would be able to assist\help.
I have a Tablix that I'm trying to populate with three separate (summed) values (Current Month, Current Year and Previous Year) from one field based on a parameter. My parameter is set as yyyymm. My expression logic is as follows for each summed value:
Sum Current Month values
=SUM(Fields!Quantity.Value),IIF(Parameters!YearMonth.Value) = CDATE(Now()), "yyyyMM")
Sum Current Year values
=SUM(Fields!Quantity.Value),IIF(Parameters!YearMonth.Value) = CDATE(Now()), "yyyy")
Sum Previous Year values
=SUM(Fields!Quantity.Value),IIF(Parameters!YearMonth.Value) = CDATE(Now()), "yyyy")-1
I'm getting the following error when attempting the above expressions:
The Value expression for the textrun Quantity5.Paragraphs[0].TextRuns[0] contains an error: [BC30205] End of statement expected
As Harry pointed out, the IIF statement syntax is
IIF([Expression to evalute], [Expression to return if true], [Expression to return if false])
Also, I think you need to format the date you get back from now() so it matches the format of your parameter.
So, taking your first expression it should be something like
=SUM(
IIF(Parameters!YearMonth.Value = FORMAT(Now(), "yyyyMM"), Fields!Quantity.Value, Nothing)
)
So starting at the inner expression, we compare the parameter to today's date formatted as yyyyMM. If the match the return the value of the Quantity field, if not return nothing.
The outer SUM then just sums all these results.
Related
I'm having a problem trying to calculate the average of period totals for periods that have non-zero totals. The data that's being returned looks like this (simplified)
Data Being Returned
and I'm displaying it like this:
Format in SSRS
What I need is to calculate the sum of all the values (27,377) divided by the number of months with non-zero totals (5). So it would be 27,377/5 = 5,475.40.
I've tried CountDistinct combined with iif without success.
Thanks
In custom code you have to create a function that will calculate month count
Public Dim months As Integer
Public Function MonthCount (month As String, val As Decimal) As Decimal
If val <> 0 Then
months = months + 1
End If
Return month
End Function
The function takes as parameters the month sum and the month name.
If the month sum if is not equal to zero it increments the month counter.
Finally it return the month value in order to display it in the matrix
In the cell of the month name value, you call the custom function.
For your average, the expression should be like the one below
Sum(Fields!val.Value, "dataset") / Code.months
Use Sum with IIF expression something like
=Sum(IIF(Fields!TotalCost.Value > 0,1, 0))
I have been trying to fetch the max of a date variable and when I try to do so, webi gives me second max date instead of the max.
[Var_tran_date]= If([Part Tran Type]="D") Then
(FormatDate(ToDate("10/10/10";"MM/dd/yy");"MM/dd/yy"))ForEach ([SBA,CAA,TDA].[Foracid])
Else
[Tran Date]
foracid here being the account number, The max varible is defined as:
var_maxdate=Max([Var_tran_date]) In ([SBA,CAA,TDA].[Foracid])
and the result is giving me second max date for each account number instead of max.
I am unable to fetch the max date.
The FormatDate() call in your variable is causing the result to be a text string value rather than date. So, your subsequent Max() is producing the maximum of the string value of the dates. In this case, "11/28/14" comes after "1/1/15".
Also the ForEach in var_tran_date is unnecessary and may be getting in the way.
Try either:
=If([Part Tran Type]="D") Then
ToDate("10/10/10";"MM/dd/yy")
Else
[Tran Date]
or
=If([Part Tran Type]="D") Then
(FormatDate(ToDate("10/10/10";"yyyy/MM/dd");"yyyy/MM/dd"))
Else
[Tran Date]
The first will retain the values as dates, so the Max() will function as expected. The second formats the dates as a string, but as yyyy/mm/dd so Max() will still produce the expected value
I'm trying to sum a net balance based on the earliest date in an SSRS report. In this case there are only 2 dates, but there can be more dates not more than 7 days.
Here's a sample of my data:
Here's what I'm trying to get with the earliest date of 10/26/15:
I've tried the following code, but not able to get this to work:
=Sum(IIf(DateDiff("d",Fields!SettleFullDate.Value,today())>=7
and DateDiff("d", Fields!SettleFullDate.Value, today())<7
and Fields!SETTLEBALANCE.Value>0), Fields!SETTLEBALANCE.Value, 0)
Update: I tried the code below and keep getting an error on the report. Could it be that I need to change the date field to an integer?
Thanks in advance for your help!
To compare the sum of values of two dates, the maximum and minimum in a set you can use the following equation
=Sum(iif(Fields!myDate.Value = Max(Fields!myDate.Value), Fields!myVal.Value, 0))
-Sum(iif(Fields!myDate.Value = MIN(Fields!myDate.Value), Fields!myVal.Value, 0))
This Sums all the values that match the maximum date in the dataset together, and sums all the values that match the minimum date in the dataset together, and takes one from the other.
It is irrespective of which dates you ask to be received, the above approach will work only against the records that you return to SSRS. So if you have a filter (WHERE clause) to return records between Date1 and Date2 this will still apply (Note - don't actually use 'Between' in the query)
Rather than using the maximum and minimum dates as listed here, you could also calculate a date similar to your original approach using
dateadd("d", -7, Fields!MySpecificDate.Value)
And insert that to the expression above.
Hopefully this is what you require - if not please let me know.
I have an issue in regards to trying to run a sql statement that returns the values of a column called month(of which I have defined as a varchar type, but only has integer values 1-12) as the associated month name. So, for example, the query would return a value of 1 as january. The issue I have is I am trying to use date_format
select date_format(month,'%M')from db.table name
but the values return as null. I was informed that the month values have to be a 'date' type in order for date_format to work. However, the values in this column 'month' are simply integers. So I run into the issue of not being able to assign the date type to the month columns because they're just integers and not correct format for dates? How could I take these single integers and return the month then?
Syntax
DATE_FORMAT(date,format)
Requires date as first param
Check out MySQL date function here:
http://www.w3schools.com/sql/sql_dates.asp
For this you can use this,
SELECT col as MonthNumber,
MONTHNAME(STR_TO_DATE(col, '%m')) as MonthName
FROM table_name
WHERE col <= 12
I've a column with values for each month of the year.
Then in parameters of my report i would be able to set the month.
SSRS should return this column with values for each month of the year (like if there's no parameter) but the sum at the bottom of this column should return the sum of the value from the beginning of the year to the selected month.
Is it possible?
Yes. If I'm understanding correctly, you want something like the image below:
Assuming your MonthYear column is a DateTime and your month parameter is an Integer, you can use an expression like the following to conditionally sum the total based on the parameter value:
=Sum(IIf(Month(Fields!MonthYear.Value) <= Parameters!Month.Value, Fields!Value.Value, 0))