RDLC Expression counting all rows where value is True - rdlc

I need to count all the values that are "True", but I have 2 datasets. I saw a lot of tutorials with one dataset and it seems easy because thay can just name the Value and it works.
The thing I tried is this
=Count(IIf((Fields!Usvojena.Value, "DataSetTackeDnevnogReda") = "True", 1, Nothing))
Fields!Usvojena.Value returns True or False
"DataSetTackeDnevnogReda" is the name of my second dataset
I get this error message:
The Value expression for the textrun
‘Textbox8.Paragraphs[0].TextRuns[0]’ has a scope parameter that is not
valid for an aggregate function. The scope parameter must be set to a
string constant that is equal to either the name of a containing
group, the name of a containing data region, or the name of a dataset.
Also for some reason Fields!Usvojena.Value is always underlined with red color in my Expression windows

You can use SUM instead of count to eliminate including "Nothing" value (and to get your count anyway) - add one only for those that have Fields!Usvojena.Value = true and zero if it's not. Also, if the field is boolean True/False, then you can do it this way:
=Sum(IIf(Fields!Usvojena.Value, 1, 0))
If the field is just a string with "True" or "False" values, then you need to add this value to comparison:
=Sum(IIf(Fields!Usvojena.Value = "True", 1, 0))
As for underlying with red color - check the field name as well.

Related

SQL query - What does taking the MIN of this boolean expression mean?

Excuse my ignorance about this... I'm taking a data analysis course and I stumbled upon this query in an exercise:
SELECT
CASE
WHEN MIN(REGEXP_CONTAINS(STRING(ActivityDate), DATE_REGEX)) = TRUE THEN
"Valid"
ELSE
"Not Valid"
END
AS valid_test
FROM
`tracker_data_clean.daily-activity-clean`;
ActivityDate is a field that contains date type data and DATE_REGEX is a regular expression variable for a date format string.
What I don't know, is what does taking the MIN() of this boolean expression REGEX_CONTAINS do or mean.
I would appreciate if any of you could help me understand the concept of doing this.
Thanks !
The query selects rows from the table and applies the REGEXP_CONTAINS() function to every (string-converted) value in the ActivityDate column. REGEXP_CONTAINS() will either return true or false based on whether the value matches the regex pattern in DATE_REGEX.
How MIN() behaves here can vary by implementation:
Booleans might be coerced as integers, so MIN() is evaluating 0's and 1's. If all the values are 1 (true), MIN() will be 1 (true), otherwise it will be 0 (false).
Other implementations might evaluate booleans directly, so MIN() returns true if all of the values are true, because the minimum value is true (true being "greater" than false), otherwise it returns false.
The result, based on the implementation, is that MIN() returns 0/1, or false/true. Either way, that result is compared to true in the CASE statement. If all values matched the regex, the comparison will be true.
Basically, the query is "does every row have a valid date in the ActivityDate column?" The result will be a table with a single column valid_test and one row, containing "Valid" if they all match, "Not Valid" otherwise.
Another way to look at it that would be relatable to some programming languages is that MIN(bool_function()) is analogous to all(), meaning return true if all values are true. Similarly, MAX(bool_function()) would be analogous to any(), meaning return true if any value is true.

The NZ() function seems not to work when called from VB, is there an alternative

I am working on an add-query.
In the add query I am trying to fill field C with with a true or false value, depending on the value in field A.
If the value in field A equals -1 the value in field C should be true (-1)
I thought that the solution would be something like the following, but I am getting #Error in the results:
C: IIf([A]='-1',True,False)
A solution that seems to return the desired outcome is the following:
B: IIf(Nz([A])='-1',True,False)
The problem with this (NZ-function) is that it throws an error when running the query with VB (ADO,DAO or OLEDB)
My question is:
What formula can be used to get to the desired results without using the NZ-function
The desired results are as given in field B
Since you're using quotes, I assume your value is a string. In that case, Nz will convert a Null to a zero-length string.
You can achieve the same by simply concatenating an empty string:
IIf([A] & ''='-1',True,False)
A more general solution is to use IIf, which allows you to specify an alternative value on nulls:
IIf(IIf([A] IS NULL, '', [A]) = '-1', True, False)
As [A] is numeric, all you need is to compare it with True:
C: [A]=True

How to write SSRS expression with OR condition involving a field and a parameter?

I have a set of tablix results that im trying to filter based on OR condition but im having difficulty combining the two into one custom expression. [IsSafetyObservation] is just a boolean field and [Department] needs to be part of the multi-selected parameter values of [#Department]. Here's a screenshot of what it looks like as two separate filters but this is doing AND condition. When I tried to write custom expression I'm not using the write syntax because I get a red line when I try to reference the #Department parameter
tablix filter screenshot
custom expression attempt
You'll need to combine your expressions into one as you tried but instead of using IN, you should use InStr. InStr searches for a string inside another string and returns the position or 0 if not found.
First you would need to combine your parameters into a string using JOIN.
JOIN(Parameters!Department.Value, ",")
This will combine your parameters into a single string that you can now search for the Department field in the Department parameter.
InStr(JOIN(Parameters!Department.Value, ","), Fields!Department.Value) > 0
Also, SSRS doesn't always work well with Booleans (ugh) - so an expression of = (1 = 1) may work in some places for a Boolean result but not others so it's best to specify:
=IIF(InStr(JOIN(Parameters!Department.Value, ","), Fields!Department.Value) > 0
OR Fields!IsSafetyObservation.Value = False,
True,
False)

How to create list as a parameter in SSRS?

I have a report in 2005 SSRS which I want to add a parameter to. The parameter would be comprised of a group of zip codes, but be selected as a single item in the list.
For example, I would like to have 5 zip codes as one selection in the list and 3 for another, etc:
Select 11111,22222,33333,44444,55555,66666 AS Boondock
Select 77777,88888,99999 AS Timbuck
Select Zip Codes NOT IN (11111-99999) AS Everything Else
So my selections in the dropdown would be:
Boondock
Timbuck
Everything Else
Can anyone help me with how I should go about creating this parameter?
Create a simple string parameter to present to the user. Let's call it ZipCodeSet.
Create a dataset that examines the #ZipCodeSet parameter and returns the appropriate list of zip codes. Call it ZipCodeSelection.
Create an internal multivaue parameter that uses ZipCodeSelection as both its Available Values and Default Values. Call it SelectedZipCodes.
Use SelectedZipCodes in your report's datasets.
The easiest solution here would probably to use a Calculated Field on your dataset, called LocationDescription, for example:
=SWITCH(Fields!ZipCode >= 11111 and Fields!ZipCode <= 66666, "Boondock", Fields!ZipCode >= 77777 and Fields!ZipCode <= 99999, "Timbuck",True, "Everywhere Else")
The lone true statement at the end is due to the SWITCH expression reading left-to-right and exiting once it evaluates one of the switches as TRUE. This way for each of the items in your table of ZipCodes you will always end up with a TRUE result.
I assume you're evaluating a range of ZipCodes, and not exact values of 11111,22222, and so on? If so, the switch will have more values. A sample of your data would help if you want an exact answer.
Once you have built your Calculated Field, you can then set up a Parameter (called #LocationParameter) with available values based on a query of your LocationDescription field, then just filter your dataset using:
Expression:
= Fields!LocationDescription
Operator: =
Value:
#LocationParameter
(if you want multiple selections on your parameter, change the operator to IN)
Hope that helps.

How to exclude one value from a grouping sum, based on a value of another field?

How do I exclude one value from a grouping sum, based on a value of another field?
ie I open Report=> Report Properties=>Code and insert my Custom Code, but how would I change the below code to exclude a numeric value of another field for the below case?
Public Function ChangeWord(ByVal s As String) As String
Dim strBuilder As New System.Text.StringBuilder(s)
If s.Contains("Others") Then
strBuilder.Replace("Others", "Other NOT INCL")
Return strBuilder.ToString()
Else : Return s
End If
End Function
I'm assuming you want to exclude a numeric value from a sum where the string value of a cell on the same row includes "Others", and that the function you've supplied is used as the grouping criteria for a table in the report. Apologies if this isn't correct.
It's not going to be possible to do this without using a second piece of logic, either a function or an Iif condition. I don't have SSRS available to test this at the moment, but (assuming your value column is an integer, the code will look something like:
Public Function ExcludeOthers(rowDesc As String, rowVal as integer)
if ChangeWord(rowDesc) = "Other NOT INCL"
Return 0
else
Return rowVal
end if
End Function
Then, in the cell where you want the conditional sum to appear:
=Sum(ExcludeOthers(Fields!desc.Value,Fields!val.Value))
Alternatively, you could do this without the function by using Iif in the cell where the conditional sum will appear:
=Sum(Iif(ChangeWord(Fields!desc.Value) = "Other NOT INCL",0,Fields!desc.Value))
Depending on the nature of your source data, you could also do this by adding calculated columns to the report's source query.
I would favour the second or third option - custom code seems like overkill for this purpose.